Representative Line: Ripping Away the Mask

This post was originally published on this site

The Daily WTF

Jason was investigating a bug in a bitmask. It should have been set to 0b11, but someone had set it to just plain decimal 11. The line responsible looked like this:

byte number = (byte) 11;

This code takes the decimal number 11, casts it to a byte, and stores it in a byte, leaving us with the decimal number 11.

Curious, Jason checked the blame and saw that one of their senior-most devs was responsible. Figuring this was a good opportunity to poke a little fun at the dev for a silly mistake like this, Jason sent them a message about the difficulties of telling apart decimal values and binary values when the decimal value only contained ones and zeroes.

“What are you talking about?” the dev replied back. “The (byte) operator tells the compiler that the number is in binary.”

Concerned by that reply, Jason started checking

To read the full article click on the 'post' link at the top.