Binary Decimal Conversion
Compiled by David Barth, 26 August 2003
General computer configuration
A central processing unit (CPU) contains 16 general purpose registers numbered 0 though 15.
Each register is 4 bytes long.
Decimal Instructions: operate on data in main storage.
Binary Instructions: operate on data in registers.
Operation field: Positions 10-14.
Mnemonic: Symbolic for a given operation.
Operands: Identify the data fields to be operated on.
Find decimal equivalent of a binary number
- Determine the positional value of each digit.
- Add the position values for all positions that contain a 1.
Example 1
- Binary number: 11111 (base 2) = 32 (base 10)
- 1x2 (4 power) + 1x2 (3 power) + 1x2 (2 power) + 1x2 (1 power) + 1x2 (0 power)
- 1x2 (4 power) = 16
- 1x2 (3 power) = 8
- 1x2 (2 power) = 4
- 1x2 (1 power) = 2
- 1x2 (0 power) = 1
- _______________________
- 32
Example 2
- Binary number: 11101 (base 2) = 29 (base 10)
- 1x24 + 1x23 + 1x22 + 0x21 + 1x20
- 1x2 (4 power) = 16
- 1x2 (3 power) = 8
- 1x2 (2 power) = 4
- 0x2 (1 power) = 0
- 1x2 (0 power) = 1
- _______________________
- 29
Remainder method for converting Decimal numbers to any other base
- Divide the number by the base.
- Indicate the remainder.
- Continue dividing into each quotient until the result is zero.
- The equivalent number is the base desired is the string of numeric remainders from the last division to
the first.
Example
Convert 38 (base 10) to base 2:
- 38/2 = 19 with a remainder of 0.
- 19/2 = 9 with a remainder of 1.
- 9/2 = 4 with a remainder of 1.
- 4/2 = 2 with a remainder of 0.
- 2/2 = 1 with a remainder of 0.
- 1/2 = 0 with a remainder of 1.
The result is a string of remainders starting with the final division, working toward the first:
100110 (base 2)
Rules for adding binary numbers
- 1 + 0 = 1
- 0 + 0 = 0
- 1 + 1 = 0, carry 1
Rules for subtracting binary numbers
- Complement the subtrahend by converting all 1s to 0s and all 0s to 1s.
- Proceed as in addition.
- Remove the high-order digit.
- Add a 1 to the total.
Example
11101 (Minuend)
11000 (Subtrahend)
_____
1. Complement the subtrahend.
11000 changed to 00111
2. Proceed as in addition:
11101
00111
_____
100100
3. Remove the high-order digit.
100100 = 00100
4. Add a 1 to the total.
00100 The result.
00001 Add 1 to the result.
_____
00101 (base 2) Final answer.
Rules for subtracting binary numbers when the subtrahend is larger than the minuend
- Complement the subtrahend by converting all 1s to 0s and all 0s to 1s.
- Proceed as in addition.
- Complement the result.
- Place a negative sign in front of the number.
Example
11000 Minuend
11101 Subtrahend
_____
1. Complement the subtrahend.
11101 changed to 00010
2. Proceed as in addition:
11000
00010
_____
11010
3. Complement the result.
11010 = 00101
4. Place a negative sign in front of the number.
-00101 (base 2) (or -101 (base 2))
Finding the binary equivalent of a negative number
- Represent the number as a positive value in binary form.
- Complement the number by replacing all 0s by 1s and all 1s by 0s.
- Add 1 to the result.
Example
1. Represent -10 in binary using 12 bits.
10/2 = 5 with a remainder of 0.
5/2 = 2 with a remainder of 1.
2/2 = 1 with a remainder of 0.
1/2 = 0 with a remainder of 1.
Result is 1010.
2. Show 12 bits:
1010 = 000000001010
3. Complement the number.
000000001010 = 111111110101
4. Add 1 to the result:
111111110101
000000000001
_____________
111111110110