High order bit is leftmost, low order (least significant) bit is rightmost. The location of each bit determines its value:

`33222222222211111111110000000000`

2

10987654321098765432109876543210

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

| | |

^{31}place 2^{10}2^{0}

What is the 32-bit unsigned binary integer representation for the decimal integer 86420?

**SOLUTION**

1.Succesively divide by 2 until the result is zero. The remainders of these divisions will be the bits
used to construct the solution.```
```

```
86420 ÷ 2 = 43210 rem 0 Low order bit
```

43210 ÷ 2 = 21605 rem 0

21605 ÷ 2 = 10802 rem 1

10802 ÷ 2 = 5401 rem 0

5401 ÷ 2 = 2700 rem 1

2700 ÷ 2 = 1350 rem 0

1350 ÷ 2 = 675 rem 0

675 ÷ 2 = 337 rem 1

337 ÷ 2 = 168 rem 1

168 ÷ 2 = 84 rem 0

84 ÷ 2 = 42 rem 0

42 ÷ 2 = 21 rem 0

21 ÷ 2 = 10 rem 1

10 ÷ 2 = 5 rem 0

5 ÷ 2 = 2 rem 1

2 ÷ 2 = 1 rem 0

1 ÷ 2 = 0 rem 1 High order bit

```
```

2. Organize the remainder bits into the binary integer:
101010001100101003. Pad the bits to the left with zeroes to bring to a total of 32:

000000000000000 101010001100101004. Convert to hex:

0000 0000 0000 0001 0101 0001 1001 010000015194

```
```
33222222222211111111110000000000

10987654321098765432109876543210

SBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

where
S = 1 for negative number, 0 for non-negativeThe remaining bits in position n represents 2

EXAMPLE

What is the 32-bit sign-magnitude binary integer representation for the decimal integer -47?

**SOLUTION**

1. S = 1, for negative number.

2. Solve as for an unsigned integer for the remaining 31 bits.

473. Organize the bits, padding with zeroes between the sign and the magnitude:_{10}= 101111_{2}

1 0000000000000000000000000 101111

4. Convert to hex:

1000 0000 0000 0000 0000 0000 0010 11118000002F

```
```

33222222222211111111110000000000

10987654321098765432109876543210

SBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

where

S = 0 for non-negative numbers

Interpretation:

the remaining 31 bits represent the magnitude of the non-negative number.

S = 1 for negative numbers

Interpretation:

Invert all the bits 2's-complement number.

Add 1.

The resulting 32 bits represent the magnitude of the negative number.

Note: this is the same as subtracting 1 from the 2's-complement number and then inverting the bits. Click here for more background.

**
EXAMPLE 1**

What is the 32-bit 2's-complement signed binary integer representation for the decimal integer -47?

**SOLUTION**

1. Solve as for an unsigned integer for the magnitude:

472. Pad with zeroes to form a 32-bit number:_{10}= 101111_{2}

00000000000000000000000000 1011113. If the value was non-negative, the answer is now complete.

4. For a negative number we must next invert all the bits:

111111111111111111111111110100005. Add one to the result:

111111111111111111111111110100016. Convert to hex:

1111 1111 1111 1111 1111 1111 1101 0001FFFFFFD1

**EXAMPLE 2**

What is the value of the 2's-complement number represented by the hexadecimal number FFFFFF99?

**SOLUTION**

1. Write out the bits:

1111 1111 1111 1111 1111 1111 1001 10012. Since the first bit is a 1 this is a negative number. We must continue. Invert all the bits.

0000 0000 0000 0000 0000 0000 0110 01103. Add 1.

0000 0000 0000 0000 0000 0000 0110 01114. Convert this result to decimal:

11001115. Since the value is negative, the original binary number was the 2's-complement representation of the decimal number -103._{2}= 103_{10}

**BINARY ADDITION OF 2'S-COMPLEMENT NUMBERS
**

Binary addition of a 2's-complement signed integer is very simple. The rules are the same as decimal addition, except that the carry of 1 happens when 1 is added to 1. That is:

```
```

```
0 + 0 = 0
```

1 + 0 = 1

0 + 1 = 1

1 + 1 = 0, carry the 1

```
```

A carry from the most significant bit position is discarded. The carry out from the most significant
bit must be the same as the carry in to that bit (either both 0 or both 1), otherwise an overflow or
underflow error has occurred.For example, using 4-bit 2's-complement signed binary integers:

```
```
0 0 1 1 note: 0011_{2} = 3_{10}

+ 0 0 1 1 = 3

---------

0 1 1 0 = 6; carry in = carry out of sign bit = 0
1 0 0 1 = -7

+ 0 0 1 1 = 3

---------

1 1 0 0 = -4; carry in = carry out = 0

1 0 0 1 = -7

+ 1 0 0 1 = -7

---------

0 0 1 0 = ERROR; 1 = carry out bit; 0 = carry in to sign bit

0 1 1 1 = 7

+ 0 1 1 1 = 7

---------

1 1 1 0 = ERROR, 0 = carry out; 1 = carry in

1 1 0 1 = -3

+ 1 1 0 1 = -3

---------

1 0 1 0 = -6; carry out = carry in = 1; carry out bit is discarded.

1 1 0 1 = -3

+ 0 0 1 1 = 3

---------

0 0 0 0 = 0; carry out = carry in = 1; carry out bit is discarded.

where`33222222222211111111110000000000`

10987654321098765432109876543210

SEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFF

`= (-1)`

^{s}2^{e-127}1.f

s = SDenormals: e = 0; Specials: (NaN, Inf, -Inf) e = 255

e = EEEEEEEE, e > 0, e < 255

f = FFFFFFFFFFFFFFFFFFFFFFF

EXAMPLE

What is the IEEE 32-bit floating point representation for the decimal number -11.5?

**SOLUTION**

1. Convert to binary. To the left of the binary point, represent the magnitude of the number to the
left of the decimal point. To the right of the binary point, represent the fraction to the right of the
decimal point (note: this may require a loss of accuracy). The first position after the binary point is
the 2^{-1} position (0.5 decimal), then 2^{-2} (0.25), 2^{-3} (0.125), *etc*.

-11.52. Convert to normalized binary scientific notation (_{10}= -1011.1_{2}

-1011.1Note: in the special case of 0.0, all 32 bits are 0. This is a denormal since there is no 1 to the left of the binary point._{2}= -1.0111 x 2^{3}

3. Determine s, e and f:

s = 1 for negative, 0 for positive.4. Assemble the 32 bits, padding f to the right with zeroes:

true exponent = 3_{10}= e - 127, thus

e = 3 + 127 = 130_{10}= 10000010_{2}

1.f = 1.0111, thus f = 0111

s e 1.fffffffffffffffffffffff

1 10000010 01110000000000000000000
11000001001110000000000000000000

5. Convert to hex:
1100 0001 0011 1000 0000 0000 0000 0000

C1380000

Note special cases:
s = 0, e=255, f = all zeroes: +Infinity

s = 1, e=255, f = all zeroes: -Infinity

s = 0 or 1, e=255, f = anything but all zeroes: Not A Number