Flipping a Byte

One of the first programming puzzles I solved on my own was a byte flip. That’s the process for taking a binary value and flipping it: You transpose bits 0 through 7 to bits 7 through 0. This is a puzzle that comes up frequently in programming, but one for which no single solution is preferred.
Continue reading

Your Card is Valid

When you type a credit card number on a website, or scan the card into a physical device, a quick calculation is performed to ensure that the card number is valid. This check happens before the bank is contacted to verify the account and the amount. The technique used to perform the quick calculation is known as the MOD 10 algorithm.
Continue reading

To Zero and Back

Many first-time programmers rush over variable type descriptions and head full-bore into coding. That’s fine. I did it. You probably did it. But eventually you encounter code that doesn’t work properly because of negative numbers. That’s when you go back and review the concept of negative integer variable types.
Continue reading

Tally the Digits

The programming adventure is full of interesting twists and turns, and with each new puzzle comes multiple opportunities to flex your coding skills and devise new solutions. For this month’s Exercise, the task is to take an integer value and add up all its digits. The mathematical term for this operation is a digit sum.
Continue reading