Binary Representation of Numbers

Binary Numbers are numbers represented with 0's and 1's.

They work much the same way as our normal decimal numbers except instead of 10 digits (0 to 9) there are only 2 digits (0 and 1).

Decimal number (subscript indicates base 10):

8401.32

= 8 x 1000 + 4 x 100 + 0 x 10 +

1 x 1 + 3 x 1/10 + 2 x 1/100

= 8 x 103 + 4 x 102 + 0 x 101 + 1 x 100 +

3 x 10-1 + 2 x 10-2

Binary number (subscript indicates base) :

1101.012 = 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 + 0 x 1/2 + 1 x 1/4

= 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2

which in base 10 is

1101012 = 8 + 4 + 1 + 1/4 = 13.2510


Practice: What is 100110.12 in base 10?

How do you add numbers in binary?


Representing Negative Integers: 2's Complement

(Integers are whole numbers - there is no decimal component. Note that negative decimal numbers will be treated very differently.)

A bit is either 0 or 1. There is no symbol for "-" so we need a way of representing negative numbers. Suppose we have 4 bits to work with. That gives is 2 4 = 16 possible combinations. Let's also say we want roughly half to be positive and half to be negative.

One possibility is to have the leftmost bit be 0 if the number is positive and 1 otherwise (sign magnitude). The remaining part of the number will represent the absolute value of the number in standard binary form.

Hex

All Positive

Binary

Sign Magnitude

2's Complement

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111

0

1

2

3

4

5

6

7

-0

-1

-2

-3

-4

-5

-6

-7

0

1

2

3

4

5

6

7

-8

-7

-6

-5

-4

-3

-2

-1

An alternative is 2's Complement: Here, negative numbers are obtained as follows:

What are advantages of 2's complement over sign magnitude?

01102 = 6

11102 = -2

---------------

01002 = 4


Hexadecimal (Hex) Format

Often we write binary numbers in hex format. This is because

What is Hex?

Hex is base 16. The "digits" are 0,1,...9,A,B,C,D,E,F.

Examples:

1016 = 1610

CA16 = 12 x 161 + 10 x 160 = 20210

Converting between Binary and Hex:

4 bits represent 16 numbers, therefore a single hex digit can be represented by exactly 4 binary digits (see table above).

1110 1010 0010 00012 = EA2116