Table of contents
Number Systems
Parent: Digital Circuits
Subject: Computer Science
Type: Semester
SL#: 2402041218
Status: Current

The term digital in digital circuits is derived from the way circuits perform operations by counting digits. A digital circuit operates with binary numbers, i.e., only in two states. The outputs of the circuit is either low 00 or high 11 in a positive logic system. In general, 00 represents zero volts and 11 represents five volts. If the situation is in reverse, it is known as negative logic system.


Number System

The decimal number system (0,1,2,39)(0,1,2,3\ldots 9), is commonly used even though there are many other number systems like binary, octal and hexadecimal, etc. It is possible to express a number in any base or radix xx. In the binary system, the base is 22. In general, any number system with radix, xx, having mm digits to the left, and nn digits to the right of the decimal point can be expressed as:

amxm1+am1xm2++a2x1+a1x0 . b1x1+b2x2++bnxna_mx^{m-1}+a_{m-1}x^{m-2}+\ldots+a_2x^1+a_1x^0\ .\ b_1x^{-1}+b_2x^{-2}+\ldots+b_nx^{-n}

Number Conversions

Decimal to binary conversion

Decimal to binary conversion can be perfomed using the divisor-remainder method, by dividing the decimal number with 2 progressively, until 0 is achieved as a quotient. Further, all the remainder after each division is written in a reverse order, which forms the binary number.

Example 1: Convert decimal number 41 to binary equivalent.

Divisor-remainder method:

2[41]
2[20]-----1
2[10]-----0
2[5]------0
2[2]------1
2[1]------0
 [0]------1

Therefore the binary equivalent is: 101001.

In case of numbers with decimal point, the part beyond the decimal point is multiplied with 2 untill a loop is achieved. The part of the result before the decimal point, is the binary part, and the part after is then multiplied with two and the process is repeated until a loop is achieved.

Example 2: Convert 41.56 from decimal to binary.

For the part before the decimal: 41

2[41]
2[20]-----1
2[10]-----0
2[5]------0
2[2]------1
2[1]------0
 [0]------1

The binary equivalent for before the decimal point is: 101001.

For the part after the decimal, 0.56, we have:

(0.56)2=1.12-----1
(0.12)2=0.24-----0
(0.24)2=0.48-----0
(0.48)2=0.96-----0
(0.96)2=1.92-----1

The binary equivalent for the part after the decimal is: 10001.

Therefore the binary equivalent for 41.56 is: 101001.10001.

Binary to decimal conversions

The binary number is first numbered starting from zero from right to left, fashion. Then binary digit is multiplied with 2 raised to the power of the position. Lets say, the binary is bb, and the position is nn, then the value at that position is:

V=b×2nV=b\times 2^n

Example 3: Convert 110010 from binary to decimal.

Firstly numbering the binary number:

Pos:  5   4   3   2   1   0
Num:  1   1   0   0   1   0

Therefore, the decimal equivalent is:

De=1.25+1.24+0.23+0.22+1.21+0.20=32+16+0+0+2+0=50\begin{align*} D_e&=1.2^5+1.2^4+0.2^3+0.2^2+1.2^1+0.2^0\\ &=32+16+0+0+2+0\\ &=50 \end{align*}

Octal number system, is a base 8 number system, which has numbers from 0,1,270,1,2\ldots7.

Hexadecimal number system, is a base 16 number system, consisting of both numbers and digits, 0,1,90,1,\ldots9, and A,B,FA,B,\ldots F.

Just like binary, other number systems have the same conversion relations with decimal numbers. When converting from decimal, the divisor-remainder method is used, with the divisor being the base of the required number system. When converting to decimal, the positional number, is multiplied with base raised to the power of position.


Exercise 1

  1. Perform the following conversions:

    1. 224 [from base 10 to base 16]
    2. B2D.F6 [from base 16 to base 10]
    3. 4C2.E6 [from base 16 to base 2]
    4. 10110.10110 [from base 2 to base 16]
  2. Convert 4447 from octal to hexadecimal using the divisor-remainder method.


Example 4: Given a relation, (244)8=(301)x(244)_8=(301)_x. Find the value of base xx.

(224)8=(301)x    2.82+2.81+4.80=3.x2+0.x1+1.x0    148=3x2+1    3x2=147    x=±7\begin{aligned} (224)_8&=(301)_x\\ \implies 2.8^2+2.8^1+4.8^0&=3.x^2+0.x^1+1.x^0\\ \implies 148&=3x^2+1\\ \implies 3x^2&=147\implies x=\pm 7 \end{aligned}

Since, base cannot be 7-7, therefore the base is 77.


Binary Arithmatic

Binary addition

Following is the chart for binary addition:

First numberSecond numberResult
000
011
101
1110 (0 carry 1)

Example 5: Add the following numbers: (26)2+(22)2(26)_2+(22)_2.

26 in binary is: 11010, 22 in binary is: 10110.

    1 1   1   1
      1   1   0   1   0
    + 1   0   1   1   0
    -------------------
    1 1   0   0   0   0

Therefore, the binary equivalent for the result is: 110000.

Binary subtraction

Following is the chart for binary subtraction:

First numberSecond numberResult
000
011 borrow 1
101
110

Example 6: Subtract 10110 from 11010.


      1   1   0   1   0
    + 1   0+1 1   1   0
    -------------------
      0   0   1   0   0

Therefore the binary equivalent for the result is: 100.

Modern Binary Subtraction

Older circuits used differnet components for addition and subtraction. Newer circuts demand more functionality in lesser space. Therefore, subtraction is performed by adding the negative of the minuant, to the subtrahend.

For example, in older circuits, 544554-45 is performed normally by deducting 4545 from 5454. But in case of modern binary subtractions, the above operation will be performed as:

5445=54+(45)\begin{align*} 54-45=54+(-45) \end{align*}

Converting the minuant to negative form has two methods:

  • 1'S Compliment
  • 2'S Compliment

1'S compliment

To find the 1'S compliment of a binary number, invert it, i.e., convert 0 to 1 and 1 to 0. For example,

1001011: (1'S) = 0110100

Steps to perform binary subtraction using 1'S compliment:

  1. Find the 1'S compliment of the negative number.
  2. Add the numbers.
  3. If carry appears, the result is positive. Add the carry with the LSB (least significant bit). Otherwise, if carry doesn't appear, the result is negative. In this case, 1'S compliment the result to get the true result.

Example 7: Perform 45 - 25, using binary subtraction using 1'S method.

45 when converted to binary gives, 101101. Now 25 gives, 11001, but we will add a zero before the number, to account for the carry as the larger number has 6 binary digits. Therefore, 25 will be written as 011001.

Now subtracting:

First finding the 1'S compilemnt of the negative number:

25 = 011001
(-25) = 100110

Second adding 45 and (-25):

45   :    101101
(-25):    100110
       ---------
Res  : |1|010011

Now since the carry appears, we will add the carry with the LSB of the result:

010011
    +1
------
010100

The final result is 010100, which in decimal equivalent is 20. The final result matches the answer.

Example 8: Perform 52-49+25 using binary techniques.

Conversion to binary equivalents:

52: 110100
49: 110001 :: (-45): 001110
25: 011001

Addition of 52 and (-49):

52   :    110100
(-49):    001110
       ---------
Res  : |1|000010

Addition of the carry to the LSB:

000010
    +1
------
000011

Addition of the first part with 25:

Res: 000011
25 : 011001
     ------
Res: 011100

Therefore, the final result is, 011100, which in decimal equivalent is 28, which matches the final answer.

In binary numbers:

MSB (most significant bit) denotes sign, i.e., 1 for negative, and 0 for positive.

E.g.:

BinarySign1'SDecimal
000+000+0
001+001+1
010+010+2
011+011+3
100-011-3
101-010-2
110-001-1
111-000-0

As you can see, there are 2 representation of zero, i.e., +0 and -0, which is mathematically not possible. As a result this serves as a major disadvantage of 1'S compliment.

2'S compliment

In order to perform 2'S compliment, invert the binary number, and add 1 to LSB.

E.g.: The binary number is 1001, then its 2'S compliment will be 0110 + 1 = 0111.

Steps to perform binary subtraction using 2'S compliment:

  1. Find the 2'S compliment of the negative number.
  2. Add the two numbers.
  3. If carry appears, the result is positive, discard the carry. If no carry appears, the number is negative, and 2'S compliment it to get the true result.

Example 9: Perform binary subtraction of 54 - 47, using 2'S compliment.

Converting decimal numbers to binary numbers:

54   : 110110
47   : 101111
(-47): 010000
           +1
       ------
       010001

Now adding, 54+(-47):

54   :    110110
(-47):    010001
       ---------
Res  : |1|000111

We will discard the carry, and the final answer is: 000111, which is equivalent to 7, in decimal format.

Example 10: Perfom binary subtraction of 47 - 54, using 2'S compliment.

Converting decimal numbers to binary numbers:

47   : 101111
54   : 110110
(-54): 001001
           +1
       ------
       001010

Adding 47+(-54):

47   :    101111
(-54):    001010
       ---------
Res  : |0|111001

Since the carry is zero, therefore the answer is negative.

Performing 2'S compliment to get the final result:

111001:: (2'S): 000110 + 1 = 000111

Therefore, the final binary result is: 000111, and since the binary was negative, the answer is: -7 in decimal forms.

When both the numbers are negative and after binary addition, the MSB is 1, consider the result negative irrespective of the carry. 2'S compliment the result to get the full result.

E.g.: (-13)-11

-13:: (2S) = 10010 + 1 = 10011
-11:: (2S) = 10100 + 1 = 10101

Adding:

-13  :    10011
-11  :    10101
       ---------
Res  : |1|01000

2'S Complimenting the result, we have:

01000:: (2'S) = 10111 + 1 = 11000

The final result is 11000 in negative, which is -24, and matches the desired result.

Binary Coded Decimal

In BCD, each number is represented seperately by binary numbers. For 2-digited numbers, the digits are written in seperate decimal numbers.

DecimalBinaryBCD
000000000
\vdots\vdots\vdots
910011001
1010100001 0000
\vdots\vdots\vdots
1511110001 0101

BCD addition

Steps to perform BCD addition:

  1. Convert decimal numbers to its BCD form.
  2. Add the numbers using binary addition rule.
  3. If the 4-bit sum is less than or equal to 9, its a BCD number. Else add 6: 0110, to make it a valid BCD number.

Example 11: Add 248 and 173 using BCD addition.

Converting the numbers into BCD form, and adding

248: 0010 0100 1000
173: 0001 0111 0011
     --------------
Res: 0011 1011 1011

But, 1011 is more than 9, therefore adding it with 0110:

Pre: 0011 1011 1011
Fix: 0000 0110 0110
     --------------
Res: 0100 0010 0001
     --------------
Dec: 4    2    1

Therefore the final result is: 0100 0010 0001, when using BCD converted to decimal, gives: 421.

BCD subtraction

Steps to perform, BCD subtraction:

  1. Convert both numbers to BCD form.
  2. Generate the 1'S compliment of the minuent and add it with the subtrahand.
  3. If 4-bit sum generate a carry, mark it. If EAC (end arround carry) generated result is positive, add the EAC with the LSB.
C+ve-ve
100001010
010100000
  1. Follow the above table and add 1010 if unmarked. If EAC is 0, the result is negative, then 1'S compliment it and follow the above table and add 1010 if marked.
  2. In the final addition, if any carry is generated, discard it.

Example 12: Perfom 127 - 73 using BCD technique.

Converting the numbers into BCD:

127  : 0001 0010 0111
73   : 0000 0111 0011
(-73): 1111 1000 1100

Adding 127 and -73:

127  :    0001 0010 0111
(-73):    1111 1000 1100
          --------------
Res  : |1|0000 1011 0011  (EAC present)
                      +1
          --------------
Pre:      0000 1011 0100
Fix:      0000 0110 0000
          --------------
Res:      0000 0101 0100
          --------------
Dec:      0    5    4

Therefore, the result is: 54.

Gray code

When arranging in binary code, the corresponding numebers might have more than one digit changed. This makes it difficult to predict, and identify anomalies. Hence Gray code was introduced, as in gray code, all corresponding numbers have only one digit that changes, thereby making it easier to understand anomalies.

DecimalBinaryGray
0000000
1001001
2010011
3011010
4100110
5101111
6110101
7111100

Steps to convert binary code to Gray code:

  1. Write the MSB as it is.
  2. If the immediate next number is same, write 0.
  3. If the immediate next number is different, write 1.

E.g.: 11010 in Gray will be:

B: G
1: 1 (MSB)
1: 0 (1-1)
0: 1 (1-0)
1: 1 (0-1)
0: 1 (1-0)

Gray: 10111

Steps to convert Gray code to binary code:

  1. Write the MSB as it is.
  2. If the immediate next number is same compared to the previous number in the result, write 0, otherwise write 1.

E.g.: Gray code: 10111 in binary will be:

G: B
1: 1 (MSB)
0: 1 (1-0)
1: 0 (1-1)
1: 1 (0-1)
1: 0 (1-1)

Binary: 11010

Exercise 2

  1. Perform the following operations using BCD:

    1. 735 - 42
    2. 105 + 24 + 415
    3. 204 - 614
  2. Convert the following from gray code to binary code:

    1. 10001
    2. 11101
    3. 01010
  3. Convert the following from decimal to gray code:

    1. 104
    2. 211
Docs
AnanyaGB
About
© MIT - 2024