Hacker News new | ask | show | jobs
by kingofpandora 2297 days ago
Genuine question - is it dangerous to memcpy X bytes that we know must be interpreted as, say, an integer?
2 comments

No. Everything is 0s and 1s after all. Take for eg. a byte. It has 8 bits and by permutating all the 0s and 1s you end up with all the possible values of a signed byte; all the numbers -128 to 127. So now, if you were to copy a byte from a random memory location that byte will just contain a permutation of 0s and 1s which when interpreted as a signed int, will simply contain a number between -128 and 127.
That's what I thought ...
Potentially. Most network protocols are big-endian while x86 is little-endian.