Number System Reviewer
Number System Reviewer
INTRODUCTION
There are infinite ways to represent a number. The four commonly associated with modern computers and digital
electronics are: decimal, binary, octal, and hexadecimal.
Decimal (base 10) is the way most human beings represent numbers. Decimal is sometimes abbreviated as dec.
Decimal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, and so on.
Binary (base 2) is the natural way most digital circuits represent and manipulate numbers. (Common misspellings
are “bianary”, “bienary”, or “binery”.) Binary numbers are sometimes represented by preceding the value with
'0b', as in 0b1011. Binary is sometimes abbreviated as bin.
Binary counting goes:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, and so on.
Octal (base 8) was previously a popular choice for representing digital circuit numbers in a form that is more
compact than binary. Octal is sometimes abbreviated as oct.
Octal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, and so on.
Hexadecimal (base 16) is currently the most popular choice for representing digital circuit numbers in a form that
is more compact than binary. (Common misspellings are “hexdecimal”, “hexidecimal”, “hexedecimal”, or
“hexodecimal”.) Hexadecimal numbers are sometimes represented by preceding the value with '0x', as in 0x1B84.
Hexadecimal is sometimes abbreviated as hex.
Hexadecimal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, and so on.
All four number systems are equally capable of representing any number. Furthermore, a number can be perfectly
converted between the various number systems without any loss of numeric value. At first blush, it seems like
using any number system other than human-centric decimal is complicated and unnecessary. However, since the
job of electrical and software engineers is to work with digital circuits, engineers require number systems that can
best transfer information between the human world and the digital circuit world. It turns out that the way in which
a number is represented can make it easier for the engineer to perceive the meaning of the number as it applies to
a digital circuit. In other words, the appropriate number system can actually make things less complicated.
Octal and hex are a convenient way to represent binary numbers, as used by computers.
Computer mechanics often need to write out binary quantities, but in practice writing out a binary number such as
1001001101010001 is tedious, and prone to errors.
Therefore, binary quantities are written in a base-8 ("octal") or, much more commonly, a base-16 ("hexadecimal"
or "hex") number format.
DECIMAL to OCTAL
Repeated Division by 8
Example
21310 = ( )8 ?
Divide-by -8 Quotient Remainder
213 / 8 26 5 Lower digit = 5
26 / 8 3 2 Second digit =2
3/8 0 3 Third digit =3
Answer = 3258
OCTAL to DECIMAL
Convert 3258 back to Decimal?
Use this table and multiply the digits with the position values
87 86 85 84 83 82 81 80
…… …… 32768 4096 512 64 8 1
DECIMAL to HEXADECIMAL
Repeated Division by 16
Example
21310 = ( )16 ?
13 / 16 0 13 Second digit =D
Answer = D516
HEXADECIMAL to DECIMAL
Convert D516 back to Decimal?
Use this table and multiply the digits with the position values
Digit 2 Digit 1
D x 161 + 5 x 160 = 13 x 16 + 5 x 1
= 208 + 5
Answer = 21310
BINARY CONVERSION
A single bit can represent two states: 0 1 Therefore, if you take two bits, you can use them to represent four unique
states: 00, 01, 10, & 11 and, if you have three bits, then you can use them to represent eight unique states: 000,
001, 010, 011, 100, 101, 110, & 111. And, if you have three bits, then you can use them to represent eight unique
states:
With every bit you add, you double the number of states you can represent.
Therefore, the expression for the number of states with n bits is 2n. Most computers operate on information in
groups of 8 bits, a unit of four bits, or half an octet, is often called a nibble (or nybble). It can encode 16 different
values, such as the numbers 0 to 15. Any arbitrary sequence of bits could be used in principle, but in practice the
most common scheme is:
0000 = decimal 00 hex 0 1000 = decimal 08 hex 8
0001 = decimal 01 hex 1 1001 = decimal 09 hex 9
0010 = decimal 02 hex 2 1010 = decimal 10 hex A
0011 = decimal 03 hex 3 1011 = decimal 11 hex B
0100 = decimal 04 hex 4 1100 = decimal 12 hex C
0101 = decimal 05 hex 5 1101 = decimal 13 hex D
0110 = decimal 06 hex 6 1110 = decimal 14 hex E
0111 = decimal 07 hex 7 1111 = decimal 15 hex F
These have perfect correspondence to Hex Group into 4's starting at least significant symbol (if the number of bits
is not evenly divisible by 4, then add 0's at the most significant end)
Write 1 hex digit for each group
Example: Convert 1001 1110 0111 0000 to Hex
After grouping follow the procedure as discussed in the previous section use the symbols of Hex number system
like 13=E
Example of
Convert 25A0 to binary
Answer = 1171608
The arithmetic operations of binary numbers, namely, addition, subtraction, multiplication and division of binary
numbers are almost similar to those of decimal system.
ADDITION
There are 3 basic rules for adding binary numbers:
0+0=0
0+1=1
1 + 1 = 0 carry over 1.
If the sum of 2 bits is greater than 1, we need to shift a column on the left. In decimal system, 1 + 1 = 2. Binary
notation of 2 is 10 (1 * 2^1 + 0 * 2^0). So we keep 0 in the 1's column and shift (carry over) 1 to the 2's column.
Example:
101 101
+ + 101
001
110 1010
MULTIPLICATION
Multiplication in binary is exactly as it is in decimal, i.e. multiply numbers right to left and multiply each digit of
one number to every digit of the other number, to sum them up. The 3 basic binary multiplication rules are also
similar to decimal.
1. 1 * 1 = 1
2. 1 * 0 = 0
3. 0 * 1 = 0
4. 0 * 0 = 0
Example:
101 101
x
x 001 101
101
110 + 000
101
11001
SUBTRACTION
Before trying subtraction, we need to understand how negative numbers are represented in binary. Whatever
system is used (i.e. 4-bit, 8-bit, 16-bit etc.), signed number must all have same number of bits. 0s are used to fill
up empty bits. We’ll use 8-bit for this tutorial. There are 3 basic standards for notating negative numbers.
Signed Magnitude
In this notation, an extra bit is added to the left of the number to notate its sign. 0 indicates +ve and 1 indicates -
ve. Using 8 bits, +13 is 00001101 and +11 is 00001011. -13 is 10001101 and -11 is 10001011.
1's Complement
In this notation positive numbers are represented exactly as regular binary numbers. So 13 will be 00001101 and
11 will be 00001011. Negative numbers are represented simply by flipping the bit, i.e. 0's become 1 and 1's become
0. So -13 will be 11110010 and -11 will be 11110100.
Subtraction Using 1's Complement
In this method the number being subtracted has to be negated using 1's complement and then added (not subtracted)
to the other number. Since signed number must all have the same number of bit, any ‘overflow’ bit has to be added
back to the rest of result.
If we want to do 13–11, its essentially 13 + (-11) or 00001101 + 11110100. Adding these will result 100000001.
Notice it is not 9 bits, so we keep the right most 8 bits 00000001 and add the ‘carry over’ 9th bit (1 in this case) to
it which gives us 00000010 = 2 = 13–11.
Now let’s try 11–13 or 11 + (-13) = 00001011 + 11110010 = 11111101. It has a 1 at the left indicating it as
negative. Using 1's complement we can figure out the absolute (positive) number which is 00000010 or 2. So the
result is -2.
2's Complement
In 2's complement a n-bit binary number is defined as the complement with respect to 2^n or simply put, the result
of subtracting the number from 2n. In this method a negative number is notated by first determining the 1's
complement of the positive number and then adding 1 to it. So 8-bit -13 will be 11110010 (1's complement) + 1 =
11110011; -11 will be 11110101.
When adding or subtracting 2's complement binary numbers, any extra (carry over) bits are discarded.
Now let’s try the same examples we tried in 1's complement.
13–11 = 13 + (-11) = 00001101 + 11110101 = 100000010. Discarding the carryover 9th bit on the left we get the
result as 00000010 = 2.
11–13 = 11 + (-13) = 00001011 + 11110011 = 11111110. A 1 at the left most bit signifies negative number. Since
this is in 2's complement, we subtract 1 from it to get the 1's complement notation of 11111101. Flipping the bits
we get 00000010 or 2, meaning our result is -2 in 2's complement notation.
While performing binary operations, it is important to know the convention being used in order to perform the
operation following the applicable rules.
DIVISION
Binary division is similar to decimal division. The only difference is that in decimal system, since we are dividing
traditional numbers, the dividend (or portion of it) can be 0, 1 or more than 1 times of the divisor. However in binary,
it can only be 0 or 1 times, i.e. the dividend (or portion of it) is >= or < than the divisor.
Let’s try dividing 6 by 3. Binary of 6 is 110 and that or 3 is 11. Following decimal division convention
We check for a portion of dividend from its left that is >= the divisor.
Then we subtract the multiple of the divisor that is <= the portion of the dividend. The multiplier (1) gets appended
to the quotient and result of the subtraction is the remainder.
We bring down 1 bit at the time (going left to right) for the remaining portion of the dividend and check if the
expression (remainder + brought down bit) is >= the divisor. If not, we append 0 to the quotient, or else we follow
step 2 again.
So the steps for 6 / 3 or 110 / 11 are Is 1 (left most bit of 110) >= 11. No (we don’t need to add 0 to quotient here
since 0s on the left are insignificant).
Is 11 (left 2 most bits of 110) >= 11. Yes. We add 1 (multiplier) to the quotient, and subtract 11 from 11. That gives
us a remainder of 0. Note, we are subtracting “one-one from one-one NOT eleven from eleven”.
Now we bring down the remaining bit (0) from 110. Is 0 >= 11. No. So we append 0 to the quotient.
Since we have no more bits remaining in the dividend, we stop here and check. Our remainder is 0 and quotient is 10
(binary) = 2.
Note: Division can become more complicated with signed numbers, and floating point binary numbers (not covered
in this Module).