Binrep


3!:1,
3!:2
,
and 3!:3
Extended
initial writing: 2000-00-00

last updated: 2004-10-26



In standard byte order, the bytes of a word are listed
from most significant to least significant; in reverse byte order,
the bytes are listed from least significant to most significant.
For example, the 4-byte integer 265358979 is 0fd10e83 in
standard byte-order and 830ed10f in reverse byte-order.
The PC is a reverse byte order machine.


The dyad x 3!:1 y applies to an array y and produces its
binary representation, according to the atom x:

  x     word size     byte order
00 32 bits standard
01 32 bits reverse
10 64 bits standard
11 64 bits reverse



The monad 3!:1 produces the binary representation
in the word size and byte order of the current machine. 3!:3
produces the hexadecimal representation of an array,
analoguous to 3!:1.
The monad 3!:2 is the inverse of 3!:1
and 3!:3, and works on an argument in
either word size and in either byte order.


The following examples were executed on a 32-bit, reverse byte order machine.

   bin  =: 3!:1
   hex  =: 3!:3
   unbin=: 3!:2
   x -: unbin bin x=: 3 1 4 1 5 _9 265358979
1
   x -: unbin hex x
1
   x -: unbin 0 bin x
1
   x -: unbin 1 bin x
1
   x -: unbin 10 bin x
1
   x -: unbin 11 bin x
1
   $ bin x
48
   _4 [ a.i.bin x
  4   0   0   0
  0   0   0   0
  7   0   0   0
  1   0   0   0
  7   0   0   0
  3   0   0   0
  1   0   0   0
  4   0   0   0
  1   0   0   0
  5   0   0   0
247 255 255 255
131  14 209  15
   _4 [ a.i.0 bin x
  0   0   0   4
  0   0   0   0
  0   0   0   7
  0   0   0   1
  0   0   0   7
  0   0   0   3
  0   0   0   1
  0   0   0   4
  0   0   0   1
  0   0   0   5
255 255 255 247
 15 209  14 131
   (hex x),.' ',.(0 hex x),.' ',.(1 hex x),.' ',.(10 hex x),.' ',.(11 hex x)
04000000 00000004 04000000 0000000000000004 0400000000000000
00000000 00000000 00000000 ffffffffffffffff ffffffffffffffff
07000000 00000007 07000000 0000000000000007 0700000000000000
01000000 00000001 01000000 0000000000000001 0100000000000000
07000000 00000007 07000000 0000000000000007 0700000000000000
03000000 00000003 03000000 0000000000000003 0300000000000000
01000000 00000001 01000000 0000000000000001 0100000000000000
04000000 00000004 04000000 0000000000000004 0400000000000000
01000000 00000001 01000000 0000000000000001 0100000000000000
05000000 00000005 05000000 0000000000000005 0500000000000000
f7ffffff fffffff7 f7ffffff fffffffffffffff7 f7ffffffffffffff
830ed10f 0fd10e83 830ed10f 000000000fd10e83 830ed10f00000000
   (hex -: 1&hex) x
1
   (0 hex y) ,. ' ' ,. 1 hex y=: o. i. 2 3
00000008 08000000
00000000 00000000
00000006 06000000
00000002 02000000
00000002 02000000
00000003 03000000
00000000 00000000
00000000 00000000
400921fb 182d4454
54442d18 fb210940
401921fb 182d4454
54442d18 fb211940
4022d97c d221337f
7f3321d2 7cd92240
402921fb 182d4454
54442d18 fb212940
402f6a7a 5e385529
2955385e 7a6a2f40
   (0 hex y) ,. ' ' ,. 1 hex y=: ;:'We the people'
00000020 20000000
00000000 00000000
00000003 03000000
00000001 01000000
00000003 03000000
00000020 20000000
00000038 38000000
00000050 50000000
00000002 02000000
00000000 00000000
00000002 02000000
00000001 01000000
00000002 02000000
57650000 57650000
00000002 02000000
00000000 00000000
00000003 03000000
00000001 01000000
00000003 03000000
74686500 74686500
00000002 02000000
00000000 00000000
00000006 06000000
00000001 01000000
00000006 06000000
70656f70 70656f70
6c650000 6c650000