Lawrence Technological University
College of Arts and Science
Department of Mathematics and Computer Sciences

Introduction to C, MCS 1142

A little knowledge of the binary number system is important to the understanding of C. The base 16 or hexadecimal number system is useful because 1 hexadecimal digit represents 4 binary digits. This compactness improves readability for humans. The base 8 or octal number system is useful for historical reasons on a Unix command line. Be aware, C and its standard library functions, which grew up with Unix, recognize a number with a leading zero as octal even if you intended decimal. Because of its efficiencies, two's complement representation of negative binary numbers has replaced sign-magnitude and one's complement representations in general use. The two's complement can be be found by adding 1 to the one's complement of the number. Being able to count from -16 to 16 should be enough for this C course.

```Examples of negative number representations:
-16 decimal, -0000 0000 binary or -10 hexadecimal in 8 bits
sign-magnitude:   1001 0000 or 90
one's complement: 1110 1111 or EF
two's complement: 1111 0000 or F0

2's Comp.
-16     1111 0000  360   F0
-15     1111 0001  361   F1
-14     1111 0010  362   F2
-13     1111 0011  363   F3
-12     1111 0100  364   F4
-11     1111 0101  365   F5
-10     1111 0110  365   F6
-9     1111 0111  367   F7
-8     1111 1000  370   F8
-7     1111 1001  371   F9
-6     1111 1010  372   FA
-5     1111 1011  373   FB
-4     1111 1100  374   FC
-3     1111 1101  375   FD
-2     1111 1110  376   FE
-1     1111 1111  377   FF
0     0000 0000  000   00
1     0000 0001  001   01
2     0000 0010  002   02
3     0000 0011  003   03
4     0000 0100  004   04
5     0000 0101  005   05
6     0000 0110  006   06
7     0000 0111  007   07
8     0000 1000  010   08
9     0000 1001  011   09
10     0000 1010  012   0A
11     0000 1011  013   0B
12     0000 1100  014   0C
13     0000 1101  015   0D
14     0000 1110  016   0E
15     0000 1111  017   0F
16     0001 0000  020   10
```

Revised January 4, 2003