Sam Pollard (2) [Avatar] Offline
#1
In the note at the beginning of Section II - Types, we state that ‘The text “Go” and the number 28487 are both represented with the same zeros and ones on an X86 computer (0110111101000111) ... "

but that first byte = 01101111 = 111 which corresponds to “o” in UTF-8
and the second byte = 01000111 = 71 = “G”
so we seem to be spelling “oG” ?

To spell “Go”, wouldn’t we need to switch the order of the 2 bytes, to form
0100011101101111 = 18287 ??

Apologies if this has been discussed already or if this is just a typo that will be sorted later.
Nathan Youngman (40) [Avatar] Offline
#2
Hi Sam,

Thanks for double checking this. Instead of doing this in my head, I wrote a little program.

https://play.golang.org/p/pJyEDCyxbk

The reason the bytes are in this order has to do with little endians on x86. See:

https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html

That said, this example doesn't account for a string having a length (Go) or null termination (C). It may be better if I simplify it to a single character (rune) and 8-bits.