A computer’s native tongue is binary, the famous ones and zeros worshiped by early mainframe programmers. Clumped into bytes and words, these digits easily represent an armada of integers, both positive and negative values. But what about fractions, decimal values, huge numbers, and teeny tiny numbers? What’s the secret to their storage?
Continue reading
Peeking at Data Stored in a Union
A C language union is a shared data space accessed via different data types. This feature can be handy, providing that you tag the union data as was seen in this Lesson. But I’m after exploiting a union for a more abusive yet useful purpose.
Continue reading
Tagging a Union
A union by itself presents some issues, which is why unions are flagged as insecure. I’ve shown some examples in last week’s Lesson. But there is a solution that provides a backstop for consistency when accessing the different data types stored as union members.
Continue reading
The Clock Angle Problem – Solution
The challenge for this month’s Exercise is to report the angle between two hands on an analog clock. The result must be positive and it must reflect the lesser of two possible degrees.
Continue reading
The Scary Part of the Union
From last week’s Lesson, you saw an example of how different data types stored in a union can be beneficial. As both structures WORDREGS and BYTEREGS overlapped to reflect the data stored in an 8086 CPU, using a union to represent the data is both practical and economic. But such conditions are rare.
Continue reading
The Clock Angle Problem
Difficulty: ★ ★ ☆ ☆
Reading an analog clock is a skill that some kids need to master these days. Oh, I’m sure that eventually everyone figures it out. When I was a kid, digital clocks were rare. No, we all learned how to tell time by looking at a round disk with 12 numbers and a big hand and a little hand. If a second hand was available, well it was just more entertainment for the terminally bored child.
Continue reading
Back When Unions Were Useful
Though it’s shunned today, using a union in your C code was common in the 1980s. Back then, compilers and IDEs such as Borland’s TurboC were customized for the MS-DOS operating system. Daring C programmers used the C language’s union keyword to access the system’s hardware directly. Scary.
Continue reading
Unions and Data Storage
A C language keyword worthy of shunning is union. It joins goto as another keyword to avoid, but union is more in the realm of the deprecated gets() function in that it has a potential for dangerous exploits. So why not have some fun with it before the C Lords banish it from the language?
Continue reading
Building a Boolean Array
Continuing from last week’s Lesson, I discovered that though the C language lets you create a Boolean array, the data is stored in char-sized integers and not true binary data. But there is a way to convert that Boolean area into binary data; it just takes some coding legerdemain.
Continue reading
Too Big – Solution
This month’s Exercise is about finding the limits, or how large a signed or unsigned char value can get before it flips over to negative or to zero. And the trick is performing this feat in your code without using the defined constants for a char data type available in the limits.h header file.
Continue reading