|
by George Martin
Start ı The
Unsigned Modifier in Action ı The Signed
Notation ı A Lesson in Subtraction
ı Sources and PDF
This month, letıs talk numbersıbinary
numbers, embedded processors, and how different numbering systems
interact with CPU instructions and the C programming language.
NUMBER TYPES IN C
The C language has some built-in number
typesıchar, int, long, and float, along
with modifiers, signed, unsigned, short, and double. These number
types have different meanings, depending on the compiler and CPU.
After I define the basic number types, Iıll focus on signed and unsigned.
Itıs good practice to use #typedefs,
so youıre sure about the amount of data you are referencing. Letıs
assume you are writing code for an 8-bit CPU, and your compiler defines
char as 8 bits, int as 16 bits, and long as 32
bits. Table 1 shows how the typefdefs would look.
|
#typedef
#typedef
#typedef
#typedef
#typedef
#typedef
|
CHAR8
UCHAR8
INT16
UINT16
INT32
UINT32
|
char
unsigned char
int
unsigned int
long
unsigned long
|
| Table
1ıDepending on what CPU and compiler you use, the typedefs
are defined differently. |
BINARY BASICS
Letıs see how the CPU works with binary
numbers. The experts may wish to skip ahead, but letıs assume you
have an 8-bit computer with a basic 8-bit register. An 8-bit register
can hold the binary patterns from 0000 0000 to 1111 1111. In a straightforward
notation, 0000 0000 represents 0 decimal and 1111 1111 represents
255 decimals. In C, this is called the unsigned modifier.
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ıCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |