The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

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 (56) [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.