Conversion Operator Tutorial

The conversion operator (data %%% code) and the endian operator (data >%< code) are provided to allow intimate study and manipulation of the bytes and even bits that make up the data. When you read a stream of alien data you may need to change the endian order, or the framing of the bytes in various character and numeric types. The left argument is the data in the form of a string, a vector of numbers, or a vector of bits. The right argument is the desired framing of the left argument data. The framing codes are related to the bytes in the content according to the following table. Notice how the codes generally relate to the type of framing (e.g. number of bytes) for the result.

Right Arg Result
0 Bits
1 Unsigned Character
_1 Character
2 Unsigned Short
_2 Signed Short
4 Unsigned Integer
_4 Signed Integer
4. Float
8. Double

Examples show what is difficult to put into words so I'll let the following examples do the talking.

Commentary Code Result
Commentary '<1>:'(123%%% 0)$;
'<2>:'(123.%%% 0)$;
'<3>:'('ABC'%%% 0)$;
<1>:01111011 00000000 00000000 00000000
<2>:00000000 00000000 00000000 00000000 00000000 11000000 01011110 01000000
<3>:01000001 01000010 01000011
Commentary '<1>*** Original n:'$; 251..258 =>n$;
'<2>*** As CHAR:'$; n %%% 1 =>c :hex$;
'<3>*** UCHAR:'(c %%% 1 )$;
'<4>*** CHAR:'(c %%% _1 )$;
'<5>*** CHAR to INT:'('âáà'%%% _1)$;
'<6>*** UCHAR to UINT:'('âáà'%%% 1)$;
<1>*** Original n:
251 252 253 254 255 256 257 258
<2>*** As CHAR:
ûüýþÿ...
FFFFF000
BCDEF012
<3>*** UCHAR:251 252 253 254 255 0 1 2
<4>*** CHAR:_5 _4 _3 _2 _1 0 1 2
<5>*** CHAR to Num:_30 _31 _32
<6>*** UCHAR to Num:226 225 224
Commentary '*** Original n'$;
123 65413 =>n;
'*** As short'$;
n %%% 2=>sh$;
'*** Back as SHORT'$;
sh %%% _2 $;
'*** Back as USHORT'$;
sh %%% 2 $;
*** Original n
123 65413
*** As short
{.…ÿ
*** Back as SHORT
123 _123
*** Back as USHORT
123 65413
Commentary '<1>:'$;(123%%% 4 :hex)$;
'<2>:'$;(123.%%% 4. :hex)$;
'<3>:'('ABCD'%%% 4)$;
'<4>:'(_1 %%% 4 %%% _4%**)$;
'<5>:'(_1 %%% 4 %%% 4%**)$;
'<6>:'(1 %%% 4.0 %%% 4.0 %**)$;
'<7>:'(1 %%% 4.0 %%% _4 %**)$;
'<8>:'(1.0 %%% 4.0 %%% 0)$;
<1>:
{...
7000
B000
<2>:
..öB
00F4
0062
<3>:1145258561
<4>:Num[R1C1:I]_1
<5>:Num[R1C1:F]4.29497e+09
<6>:Num[R1C1:F]1
<7>:Num[R1C1:I]1065353216
<8>:00000000 00000000 10000000 00111111
Commentary ('*** Original x:')$;
  (123.4 =>x %**)$;
('*** y: (x as string)')$;
  (x %%% 8 =>y :hex)$;
('*** Back to x:')$;
  (y %%% 8. %**)$;
*** Original x:
Num[R1C1:F]123.4
*** y: (x as string)
.....À^@
00000C54
000000E0
*** Back to x:
Num[R1C1:F]123.4
Commentary '<1>:'(0 %%% 0=>b)$;
'<2>:'(#true =>[10]b;b)$;
'<3>:'(b %%% 4)$;
'<4>:'(b >%< 4 %%% 4)$;
'<5>:'(1024 %%% 0=>b)$;
'<6>:'(b >%< 4=>eb)$;
'<7>:'(32-(eb ` 1))$;
'<8>:'(eb %%% 4)$;
'<9>:'(eb >%< 4 %%% 4)$;
<1>:00000000 00000000 00000000 00000000
<2>:00000000 01000000 00000000 00000000
<3>:16384
<4>:4194304
<5>:00000000 00000100 00000000 00000000
<6>:00000000 00000000 00000100 00000000
<7>:10
<8>:262144
<9>:1024
Commentary '<1>:'(1234 %%% 4=>c %%% 0)$;
'<2>:'(c >%< 2 %%% 0)$;
'<3>:'(c >%< 4 %%% 0)$;
'<4>:'(1/7 %%% 8.=>c %%% 0)$;
'<5>:'(c >%< 8 %%% 0)$;
<1>:11010010 00000100 00000000 00000000
<2>:00000100 11010010 00000000 00000000
<3>:00000000 00000000 00000100 11010010
<4>:10010010 00100100 01001001 10010010 00100100 01001001 11000010 00111111
<5>:00111111 11000010 01001001 00100100 10010010 01001001 00100100 10010010