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
String Storage Mysteries
String storage is one of those frustrating things in the C language. Specifically, it’s that null character, \0, that appears at the end of every string. Is that character counted when you input a string? Copy a string? Create storage for a string? It’s a mystery that could drive you nuts.
Continue reading
The pow()erful Function
When I first learned the C language, I was surprised to find something missing from its assortment of operators. The +, -, *, and / operators are pretty common for nearly all programming languages. And you’ll find the % and ! operators used for modulus and logical NOT in a few programming languages. Yet what other languages have that C lacks is an exponent or power operator.
Continue reading
All Files Have a Number
The common way for humans to describe a file is to use its name. You refer to hello.txt as a file. The fopen() function C uses this nomenclature, which is handy and convenient. While a program runs, however, a file number is assigned to an open file.
Continue reading
Find the Best Size Container – Solution
The C library contains various mathematical rounding functions, such as ceil(). That function, however, rounds up floating point values to the next integer. For this month’s Exercise, your job was to round up an integer to multiples of 16: 16, 32, 48, and 64.
Continue reading