A programmer was sentenced to 255 days in jail. He asked the judge if he could make it 256 days instead. The judge granted his request and the programmer walked free the next day.

Ok, I'm guessing this has something to do with 256 bits making up a single byte... but I still don't get it. 🤔

@zalasur @Blort @climagic

Yes but the OP didn't define the type of the "sentence" variable ?
So was it a lucky guess from the programmer ?

@Blort 8 bits make up a single byte.
255 = 0b11111111
Add one and you get 0b100000000.
But if you only have 8 bits, the additional 1 at the front is lost, leaving: 0b00000000, thus turning the 255 day sentence into a 0 day sentence due to an overflow.

@climagic At least in Switzerland trains are not allowed to have exactly 256 axles. ¯\_(ツ)_/¯

@adi @climagic
In binary, 2^8 is a 1 followed by 8 zeros. If the value is stored in 8 bits, there's an overflow. The value stored is the 8 zeros and the 1 is lost 🤓 👍

@climagic This #joke is really #funny for us techies, but it isn't going to register with everyone.

#geek #humor

@climagic 255 should be okay if he starts to count the day from zero ^^


Also funny because there's probably at least one court database system in current use where this is true...

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!