Difference between revisions of "Big endian"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
m
 
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
  0000000 6568 6c6c b6c3 7720 726f 646c 000a
 
  0000000 6568 6c6c b6c3 7720 726f 646c 000a
 
  000000d
 
  000000d
OK, we have a file that contains the string "hellö world".
+
OK, we have a file that contains the string "hellö world". We read the first byte and it is a "h":
 
  tstaerk@little:~> dd if=test bs=1 count=1 | hexdump
 
  tstaerk@little:~> dd if=test bs=1 count=1 | hexdump
 
  0000000 0068
 
  0000000 0068
Line 15: Line 15:
 
  1+0 records out
 
  1+0 records out
 
  1 byte (1 B) copied, 0.00075077 s, 1.3 kB/s
 
  1 byte (1 B) copied, 0.00075077 s, 1.3 kB/s
  tstaerk@d3ll:~> dd if=test bs=1 count=1 skip=1 | hexdump
+
We read the second byte and it is an "e":
 +
  tstaerk@little:~> dd if=test bs=1 count=1 skip=1 | hexdump
 
  1+0 records in
 
  1+0 records in
 
  1+0 records out
 
  1+0 records out
Line 21: Line 22:
 
  0000000 0065
 
  0000000 0065
 
  0000001
 
  0000001
 +
Let's read the 5th byte:
 +
tstaerk@little:~> dd if=test bs=1 count=1 skip=4 | hexdump
 +
1+0 records in
 +
1+0 records out
 +
1 byte (1 B) copied, 4.533e-05 s, 22.1 kB/s
 +
0000000 00c3
 +
0000001
 +
On the big endian machine:
 +
big:root> cat test
 +
hellö world
 +
big:root> dd if=test of=test2.txt bs=1 count=1 skip=4
 +
1+0 records in
 +
1+0 records out
 +
Back on the little endian machine:
 +
tstaerk@little:~> scp root@big:test2.txt .
 +
root@big's password:
 +
test2.txt                                                                                                                                  100%    1    0.0KB/s  00:00
 +
tstaerk@little:~> hexdump test2.txt
 +
0000000 00c3
 +
0000001
 +
OK, result: the bytes itself do not get mixed.

Latest revision as of 11:42, 12 December 2010

Today I am experimenting with my big endian (PowerPC) machine

tstaerk@little:~> cat >test
hellö world
tstaerk@little:~> cat test
hellö world
tstaerk@little:~> hexdump test
0000000 6568 6c6c b6c3 7720 726f 646c 000a
000000d

OK, we have a file that contains the string "hellö world". We read the first byte and it is a "h":

tstaerk@little:~> dd if=test bs=1 count=1 | hexdump
0000000 0068
0000001
1+0 records in
1+0 records out
1 byte (1 B) copied, 0.00075077 s, 1.3 kB/s

We read the second byte and it is an "e":

tstaerk@little:~> dd if=test bs=1 count=1 skip=1 | hexdump
1+0 records in
1+0 records out
1 byte (1 B) copied, 4.436e-05 s, 22.5 kB/s
0000000 0065
0000001

Let's read the 5th byte:

tstaerk@little:~> dd if=test bs=1 count=1 skip=4 | hexdump
1+0 records in
1+0 records out
1 byte (1 B) copied, 4.533e-05 s, 22.1 kB/s
0000000 00c3
0000001

On the big endian machine:

big:root> cat test
hellö world
big:root> dd if=test of=test2.txt bs=1 count=1 skip=4
1+0 records in
1+0 records out

Back on the little endian machine:

tstaerk@little:~> scp root@big:test2.txt .
root@big's password:
test2.txt                                                                                                                                   100%    1     0.0KB/s   00:00
tstaerk@little:~> hexdump test2.txt
0000000 00c3
0000001

OK, result: the bytes itself do not get mixed.