Implementing a written algorithm is something you do frequently as a C language programmer. You’re given a set of directions and your job is to translate that English into computer code — and make that code work.
Continue reading
Author Archives: dgookin
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
Reading a Binary Fraction
As an example of how a binary values can hold fractions, I’ve concocted a simple real number format: An 8-bit value with 4 bits representing the whole number portion and 4 bits representing the fractional portion. Here’s how it looks:
Continue reading
Binary Fractions
Over the past few weeks, I’ve covered the concept of negative integers and their representation as binary values. What can also be represented in binary, something that’s even less obvious than negative values, are fractions.
Continue reading
More Negative Integers
The far left bit in a signed integer value — no matter how wide the integer — is the sign bit. If it’s set, the value is negative. Otherwise, the value is positive. But the sign bit is more than just a minus sign. It also plays into binary math.
Continue reading
Making Negative Integers
In the C language, you have several ways to create a negative integer: You can assign a negative value to a variable, you can perform math that results in a negative value, or you can manipulate bits to convert a positive value to a negative one. That final operation isn’t as easy as it sounds.
Continue reading
Tally the Digits – Solution
To solve this month’s Exercise, you must create a function that tallies digits in an integer value, what’s known as a digit sum. The key issue is how to peel off individual values in an integer and then total the result.
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