Saturday 23 February 2019

TWO's COMPLEMENT

This section is divided into
1. What is the significant of LSB
2. What is the Significant of MSB
3. What is Complement in computer science
4. What is One's Complement
5. What is Two's complement

Least significant bit - 
The least significant bit in the Binary number is the UNIT value,  Least significant bit helps to determine if the number is the ODD or the EVEN Number.

How to determine if the number is ODD or EVEN ?
The simplest way is to use modulo(%) operator 

pseudo code - 
if  no % 2 == 0 then
     print "even number"
else 
     print "odd number"

using binary operation ?
example number 2 in binary format is represented as 10 and number 3 in binary format is represented as 11

Bit-wise  And (&) operator can be used to determine if the number is the ODD no or EVEN no.
Truth Table
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0 

hence 

Binary format of 2 -->    1  0
Binary format of 1 -->    0  1
                                     &
--------------------------------------
                                            0

Hence the no is even no

     
Binary format of 3 -->    1  1
Binary format of 1 -->    0  1
                                     &
--------------------------------------
                                            1

Hence the no is ODD No


Most significant bit - 
Most significant bit is the (or higher order bit) is the bit position in binary number having greatest value.

The MSB can also correspond to the sign bit of a signed binary number in one's or two's complement notation, "1" meaning negative and "0" meaning positive


What is Complement in Computer Science ?

the method of complements is a technique used to subtract one number from another using only addition of positive numbers.

One's complement

One's complement is inverting bit i.e changing '0' to '1' and vice versa .

Two's Complement

do One's complement  and add one. 

example 
100 - 22 = ?








No comments:

Post a Comment