While I was writing the Maths for Programmers course, I was constructing some examples to illustrate overflow and noticed a strange pattern. I was working with the number 255, which is the biggest number that can be stored in an unsigned byte, and is represented in binary by 1111 1111. The idea was to use the unsigned byte data type and show the results of calculating 255 + 255 and 255 * 255 – both of those will cause an overflow.

Now 255 + 255 gives 510. And 255 * 255 gives 65,025. Look at what these numbers look like in binary. Continue reading “A Strange Binary Pattern”