× back Data representation Binary, Octal and Hex-decimal number systems Arithmetic operation on Binary numbers r's and r-1's complement Subtraction of decimal using 10's and 9's complemnet Overflow & underflow Fixed and floating point representation ASCII code Gray code Excess-3 code BCD PYQs
Next Topic → ← Previous Topic

Number System

Data Representation

Quantifying Bits and Bytes

  • A byte is composed of eight bits.
  • Transmission speeds are expressed in bits, whereas storage space is expressed in bytes.

Binary, Octal and Hex-decimal number systems

Arithmetic operation on Binary numbers

Binary addition

                        
                
                                     sum  carry 
                            0 + 0  =  0     0
                            1 + 0  =  1     0
                            0 + 1  =  1     0
                            1 + 1  =  0     1

                            example ↓

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

Binary subtraction

                        

                            1 1 1 0
                            - 1 1 1
                            ------- 
                            0 1 1 1  
                            
                              1 1 0 1 1
                            - 1 0 1 1 0
                              --------- 
                              0 0 1 0 1
                        
                    

Binary multiplication

                        

                                product
                                    ↓                              
                            0 x 0 = 0
                            1 x 0 = 0
                            0 x 1 = 0
                            1 x 1 = 1

                            example ↓ 

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


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

Binary division

1's complement

  • 1's complement of a binary number is obtained simply by replacing each 1 by 0 and each 0 by 1.
  • Example ↓

                        

                            0 1 1 0 0 1
                            ↓ ↓ ↓ ↓ ↓ ↓
                            1 0 0 1 1 0
                        
                    

2's complement

  • 2's complement of a binary number can be obtained by adding 1 to it's 1's complement.
  • Example ↓

                        

                            0 1 1 0 0 1 ← number 
                            1 0 0 1 1 0 ← 1's complement 
                                    + 1 ← add 1 to 1's complement
                            ------------ 
                            1 0 0 1 1 1 ← 2's complement
                        
                    

  • Shortcut for 2's complement
  • Steps ↓
    1. Write down the given number.
    2. Starting from LSB, copy all the zeros till the first 1.
    3. Copy the first 1.
    4. Complement all the remaining bits.

                        

                            1 0 1 1 1 0 0 0 
                                  ↓ 
                            0 1 0 0 1 0 0 0
                        
                    

Subtraction using 1's and 2's complement

  • Before using any complement method for subtraction equate the length of both minuend and subtrahend by attaching zeros.
  • Following are the rules for subtraction using 1's complement.
    1. Take 1's complement of subtrahend.
    2. Add this complement to minued.
      • 5 - 7, here 7 is subtrahend and 5 is minued.
    3. If a carry is produced by addition then add this carry to the LSB of result. This is called as end around carry (EAC).
    4. If no carry generated result is negative, and is in 1's complement form. Take 1's complement of result and assign -ve sign to it.

Example 1. Perform following subtraction using 1's complement.
(i) 7 - 3
(ii) 3 - 7

Solution. (i) 7 - 3

Solution. (ii) 3 - 7

2's complement subtraction

  • Method of 2's complement is similar to 1's complement subtraction except the end around carry (EAC). The rules are listed below.
    1. Take 2's complement of subtrahend.
    2. Add this complement to minued.
    3. If a carry is produced, then discard the carry and the result is positive. If no carry is produced result is negative and is in 2's compliment form.

Example 2. Perform following subtraction using 2's complement.
(i) 7 - 5
(ii) 5 - 7

Solution. (i) 7 - 5

Solution. (ii) 5 - 7

r's and r-1's complement

notes


Subtraction of decimal using 10's and 9's complement

10's complement subtraction

Steps ↓

  1. Find 10's complement of subtrahend.
  2. Add 10's complement of subtrahend to minuend.
    1. If there is a carry then drop it and you will get your result in positive.
    2. If there is no carry then find 10's complement of your result and your result will be in negative.

9's complement subtraction

Steps ↓

  1. Find 9's complement of subtrahend.
  2. Add 9's complement of subtrahend to minuend.
  3. If there is a carry then add it to result and your answer will be in positive.
  4. If there is no carry then find 9's complement of your result and your answer will in negative form.

Overflow & underflow

Fixed and Floating Point Representation

Fixed Point Representation

  • In fixed point notation, there are a fixed number of digits after the decimal point. Fixed point representation has a fixed number of bits for the integral and fractional parts. There are three parts of the fixed-point number representation: Sign bit, Integral part, and Fractional part. The below figure depicts it.

    Sign bit: The fixed point number representation uses a sign bit. The negative number has a sign bit 1, while a positive number has a bit 0.
    Integral Part: The integral part depends on the register's size; for an 8-bit register, the integral part is 4 bits.
    Fractional part: Fractional part is also of different lengths at different places. It depends on the register's size, like in an 8-bit register, integral part is of 3 bits.
    • 8 bits = 1 Sign bit + 4 bits (integral) + 3 bits (fractional part)
    • 16 bits = 1 Sign bit + 9 bits (integral) + 6 bits (fractional part)
    • 32 bits = 1 Sign bit + 15 bits (integral) + 9 bits (fractional part)
  • If we want to store 4.5
    • Step 1: We will convert the number 4.5 to fixed-point notation with the following format.

Floating Point Representation

  • Floating Point representation doesn't reserve any specific number of bits for the integer or fractional parts. But instead, it reserves certain bits for the mantissa and the exponent.
  • The floating-point representation has two types of notation:
    1. Scientific notation: it uses a x be form. It is further converted into floating-point representation. For example, Number = 32635
      Number in Scientific Notation = 32.625 x 103
      Number is binary form = 1101.101 * 2101
    2. Normalization notation: It is a special case of scientific notaiton. Normalized means that we have at least one non-zero digit after the decimal point.
      A floating-point representation has three parts: Sign bit, Exponent Part, and Mantissa. We can see the below diagraam to understand these parts.

      Sign bit: A negative number has a sign bit 1, while a positive number has a sign bit 0. The sign of any number depends on mantissa, not on exponenet.
      Mantissa Part: The mantissa part is of different lengths at different places. It depends on registers like for a 16-bit register, and mantissa part is of 8 bits.
      Exponent Part: It is the power of the number. It depends on the size of the register. For example, in the 16-bit register, the exponent part is of 7 bits.
  • How to write numbers in Floating-point notation
    • Let the number is 53.5
      step 1: We will convert the number 53.5 to binary form 53.5 =110101.1
      step 2: Normalize the number (base 2) = (1.101011)*25.
      step 3: Represent the binary number in floating-point notation with the following format.

ASCII Code


Gray Code

Binary to Gray code conversion lecture

XOR table

  • copy the most significant bit as it is
  • ( b4 b3 b2 b1 b0 )2 = b4 ( b4 ^ b3) ( b3 ^ b2 ) ( b2 ^ b1 ) ( b1 ^ b0 )

Example 1

                    

                        1  0  1  1 = 1 ( 1 ^ 0 ) ( 0 ^ 1 ) ( 1 ^ 1 )
                                   = 1     1         1         0
                        (1011)2 = (1110)gray
                    
                

Example 2

                    

                        11001 = 1 ( 1 ^ 1 ) ( 1 ^ 0 ) ( 0 ^ 0 ) ( 0 ^ 1)
                              = 10101
                    
                

Excess-3 code

                

                    Decimal  BCD   X-3
                      0     0000   0011
                      1     0001   0100
                      2     0010   0101
                      3     0011   0110
                      4     0100   0111
                      5     0101   1000
                      6     0110   1001
                      7     0111   1010 
                
            

BCD

BCD Addition

  • In many application it is required to add two BCD numbers. But the adder circuits used are simple binary adders, which does not take care of peculiarity of BCD representation. Thus we must verify the result for valid BCD by using following rules:
    1. If the sum is less then or equal to 9, it is valid BCD number.
    2. If sum is greater than 9, it is invalid. Add 6 (0110) to the sum, to make it valid.
    3. If a carry is generated when 6 is added, attach this carry at MSB.
  • Example 1. Add the following BCD numbers. (i) 1000 and 0101 (ii) 00011001 and 00011000
    Solution. (i)
                                
    
                                       1 0 0 0  →   8
                                     + 0 1 0 1  → + 5
                                     ----------- ----- 
                                       1 1 0 1    13
    
                                    since, (1101)2 > (9)10 add 6 (0110) to it
                                               1 1 0 1
                                               0 1 1 0
                                               ------- 
                                            1   0 0 1 1
                                            ↓     ↓ 
                                            1     3
                                    So, result = 00010011
                                
                            
    Solution. (ii)
                                
    
                                          1   ← ← ← Carry generated
                                    0 0 0 1   1 0 0 1 →  19
                                    0 0 0 1   1 0 0 0 → +18
                                    -----------------   ---- 
                                    0 0 1 1   0 0 0 1    37
                                    Since, a carry is generated we must add 6 (0110) to it.  
    
                                    So,      0 0 1 1   0 0 0 1
                                                       0 1 1 0
                                            ------------------- 
                                             0 0 1 1   0 1 1 1   → (37)10    
                                    So, result = 00110111
                                
                            

Error Detection and Error Correction

We know that data is transmitted in binary form.
While transmission of data, if noise are added to the data then it will not be same in receiving side as it will contain some error.

There are two types of parity bit code

1- Even parity bit code

  • It ensures that message including parity bit must contain even number of 1's.

2- Odd parity bit code

  • It ensures that message including parity bit must contain odd 1's.

Drawback of parity bit code

  1. Only single bit error can be deducted.
  2. Can't tell in which position the bit is manipulated.

Hamming code

  • It is an error detecting and correcting code.
  • It uses a number of parity bits located at certain positions.

How many parity bit can 'm' number of bit message can have?


Now we will see where to place the parity bits within the message.

Let the code is of 7 bits.
There is a rule: the parity bits can always be place at position 2n where n = 0, 1, 2, 3, ...

What will be the value of parity bits?

Example question:
Encode the binary word 1011 into seven bit even parity hamming code.

Determine the hamming code for 10111 for odd parity.

Assume that the even parity hamming code 0110011 is transmitted & that 0100011 is recevied. The receiver does not know what was transmitted, determine the error location.

Previous year questions

Convert the following:

  1. (652)10 = ( )2
  2. (25.32)8 = ( )10
  3. (6864)10 = ( )16
  4. (1011)2 = ( )8
  5. (5D2)16 = ( )8
  6. (011010110)2 = ( )8
  7. (155)8 = ( )2
  8. (10101.01)2 = ( )10
  9. (BF4A)16 = ( )8
  10. (6FBC)16 = ( )8
  11. (1010)2 = ( )2 = ( )10
  12. (72.45)10 = ( )2 = ( )16
  13. (EFF2.F)16 = ( )8 = ( )10
  14. (100101.1101)2 = ( )8 = ( )10
  15. (2341)5 = ( )10 = ( )16

Perform the following operation using 2's complement method:

  1. (-29)10 + (35)10
  2. (-33)10 + (-67)10
  1. Encode data bits 0101 into a 7 bit even parity Hamming code.
  2. A 7 bit Hamming code is received as 01011101. Check whether it is correct or not? If it is incorrect, find the correct code.

How is error detection and correction carried out using parity method in digital data transmission?

Explain grey code and excess-3 code. Encode the following into grey code and excess-3 code.

  1. 45
  2. 26

Explain BCD code and Excess-3 code. Represent the following in decimal number binary form using BCD code and Excess-3 code.

  1. 317
  2. 89
  3. 565
  4. 67

What do you mean by r's and r-1's complement? Find out the r's and r-1's complement of the following numbers:

  1. (10011)2
  2. (54)10
  3. (10101011)2
  4. (87)10

References