This month’s Exercise is to simulate turns in a game of tic-tac-toe (naughts and crosses). So the solution requires that you randomly work through available squares in the game matrix, alternating placement of an 'x' or 'o' token.
Continue reading
Non-Identical Yet Very Similar
Computer’s are notoriously obedient and serious. They’re exact. If you give them inaccurate instructions or bad data, the computer does its job without question. But the real world isn’t binary and often times it’s necessary to add some forgiveness into your code.
Continue reading
Take Your Turn
The game of Tic-Tac-Toe, also called Noughts and Crosses, provides a fertile field to plow for any budding programmer. It involves a matrix (array), logic, decisions, and all sorts of fun. If you haven’t yet coded your own Tic-Tac-Toe game, I urge you to do so, but that’s not the topic for this month’s Exercise.
Continue reading
That’s Not the Input I Asked For
I recently had a reader submit a question regarding input. He wanted to write code that would read a character and display that character’s ASCII code value. It sounds like a simple program, but you must understand variable types and the scanf() function’s peculiarities to properly code it.
Continue reading
Basic Output
The typical first program taught to anyone learning C (or any other programming language) is Hello, world! It’s fun, which sets up false expectations, but it’s also genius.
Continue reading
The byteflip() Function
When I recently researched byte-flipping on the Internet, I was surprised that the solution I used back in the 1980s wasn’t listed among the top solutions available today. That’s probably because my brain thinks like an Assembly Language programmer, so I crafted a low-level solution.
Continue reading
Your Card is Valid – Solution
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
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