4 ms·
I read this What happens if we have the number 256 in an 8-bit unsigned integer (1111 1111 in binary) and we add 1? The answer (257) needs a 9th bit (1
by rzzzwilson 9y ago
I read this
What happens if we have the number 256 in an 8-bit unsigned
integer (1111 1111 in binary) and we add 1? The answer
(257) needs a 9th bit (1 0000 0000).
and I didn't read any further. I don't think many interviewers would be eager to continue after hearing that, either.
- ahjones 9y agoI think you're being a little bit unfair. The same block then continues: This is called an integer overflow. At best, we might just get an error. At worst, our computer might compute the correct answer but then just throw out the 9th bit, giving us zero (0000 0000) instead of 257 (1 0000 0000)! (Python actually notices that the result won't fit and automatically allocates more bits to store the larger number.) The article is introducing the concept of integer overflow.
- ldite 9y ago1111 1111 = 255 1 0000 0000 = 256 Anyone who claims to understand integer overflow from actual experience, rather than memorizing textbooks, should know that by inspection. I'd forgive that in a CS grad (possibly) but if someone claimed to have been working in C or other unsafe languages for more than a trivial amount of time I'd be very suspicious.
- elldoubleyew 9y agoWell he did say he didn't read any further.
- gameguy43 9y agoFixed!