Sunday, October 21, 2012

HEXADECIMAL NUMBER OPERATION

++++HEXADECIMAL ADDITION++++


  • Unlike decimal system (base 10) with 10 digits and also binary system (base 2) with two digits, hexadecimal system (base 16) has 16 digits for its operation.

DECIMAL
4-BIT BINARY
HEXADECIMAL
0
0000
0
1
0001
1
2
0010
2
3
0011
3
4
0100
4
5
0101
5
6
0110
6
7
0111
7
8
1000
8
9
1001
9
10
1010
A
11
1011
B
12
1100
C
13
1101
D
14
1110
E
15
1111
F
Comparison between decimal, binary, and hexadecimal system…
  • Note: for hexadecimal system, from number 10 start we represent with alphabet A until number 16 and alphabet F. Let do some exercise !!



5 816
+2 216
7 1016 <---- Final answer will write 7A base 16.

Column 1 : Like decimal system, 8+2=10..... BUT the 1 will not carry out.. It will stay...
Column 2 : Do 5+2=7.....
Column 3: Final step.... convert the number 10 into hexadecimal format... which is A.... DONE !!!



  • ::::::::::Another example which are more complicated:::::

D
F16
+
A
C16




1310+1010+110=2410
1510+1210=2710

2410-1610=810
2710-1610=1110

=816


1 will carry
1 will carry


  1. Column 1: F+C=15+12=27.... But remember in hexadecimal system, only have 16 digits.. So we need use 27-16=11. The number 11 in hexadecimal system,so no need subtract again. Once we subtract one time, we need carry 1.
  2. Column 2: We solve D+A+1 = 13+10+1 = 24. Once again 24 exceed 16 digits in hexadecimal system... So we use same method in column 1, and we will get 8 and 1 will be carry.
  3. Final step, we write the answer as 18B16...

----------HEXADECIMAL SUBTRACTION--------



  • For subraction, we need do more conversion in order to solve the question. We need to convert hexadecimal number into binary number, then we need find 2's complement. Convert back into hexadecimal number then number then add two number. NOT UNDERSTAND ????!!! Come we do an example together.....
EX.......
8416-2A16


....1's compliment of 2A16 = 0101010
..... 2's compliment of 2A16 = 0101010+1---->11010110
......convert back into hexadecimal number ------> +D616
........Then add two number together, FOLLOW WHAT WE HAD DONE ABOVE, which we will get 15A16.... BUT we will drop the 1, cause the 1 represent negative in 2's compliment .
....... So final answer is 5A16.




Finally we have some links and video that maybe helpful to you all to understand more.

We also include some youtube video ..




BASIC BINARY OPERATION

BASIC BINARY NUMBER OPERATION


  • binary number operation is a bit different from what we do in normal mathematic operation. Binary number system only contain TWO numbers which are 1 and 2.


++++++ADDTION ++++++++


  • There are four simply rule that we must follow......
                             
RULES
0+0=0
0+1=1
1+0=1
1+1=10
1+1+1=11
THE RULES OF ADDITION
Let we have some example to make it clear..

      1  <------------- This is call carried bit                                                                                                      
       11             (like normal addition, the second digit will stay,other will be carried forward)  
+       1              COLUMN 1: use 1+1=10... WRITE 0..... 1 carry forward..
     100              COLUMN 2: use 1+1=10......WRITE 10...

--------------SUBTRACTION----------

  • For subtraction,there are also some simply rules to follow....
RULES
0-0=0
0-1=1
( borrow from the next binary number)
1-0=1
1-1=0
THE RULE FOR SUBTRACTION

                  02   <------if cant minus 0 with 1, borrow from left side number)
                  101     COLUMN 1 : use 1-0=1...... WRITE 1...         
                  10     COLUMN 2: cannot minus 1 with 0.... borrow 2 from left side number 1.. the
                    11                      1 become 0... 2 minus 1.. WRITE 1..
                                    COLUMN 3: after borrow by 0.... left only zero... so no need write.





* * * * MULTIPLICATION * * * *

  • For binary multiplication we only need to follow few rules below ...
Rules of Multiplication
0 x 0 = 0
0 x 1 = 0
1 x 0 = 0
1 x 1 = 1
  • example of binary multiplication :
  •     101
        x
    11  
        
    101 < firstly, we multiply 101 to 1
      1010 < Then we put a 0 as a placeholder as we would in decimal multiplication, and  multiply 101 by 1
      1111  < at the end, we add 101 to 1010 then we can get the answer  



÷ ÷ ÷ ÷ ÷ ÷ DIVISION ÷ ÷ ÷ ÷ ÷ ÷

  • Division is easy and involves our knowledge of binary multiplication.
  • example of binary division of 1011 into 11
                 11   R=10
        11 )1011
              -11
                101
                -11
                  10  <-- remainder, R

      To check our answer, we can multiply our divisor 11 by our quotient 11. Then we add its' product to the remainder 10, and compare it to our dividend of 1011.

          11
       x 11
         11
       11 
     1001  < product of 11 and 11
 
    1001
   +  10  < remainder 10
    1011  < sum of product and remainder
   
     The sum is equal to our initial dividend, therefore our solution is correct.

here are some link that can refer...
http://www.ustudy.in/node/7598
http://www.exploringbinary.com/binary-multiplication/







Number System

Number System

A number system is a basic symbol to represent a set of quantities. There are a lot of number system. Here we only focus on the decimal, hexadecimal and binary number.

Most if the numbering system will have a base. The maximum number that can be represented on the single digit or number is called base.

Decimal number
  • Base of 10
  •  The value of the assigned weight is composed by 10 digits starting from 0-9
Binary number
  • Base of 2
  • The number consists of only two digits which is 0 and 1
Hexadecimal number
  • Base of 16
  • The composed number is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
                                              
 Number System Cenversion

 Second Complement Number

In microprocessor-based equipment, second complement method of representing number is commonly used. Until now, we only assume that the numbers are positive. However, microprocessor must proceed both positive and negative number.

Assume a microprocessor have 8 register bits. The most significant bit (MSB bit which is first bit from left) is 0, then the number is positive (+). Conversely, the MSB bit is 1, then the number is negative (-). The other remaining 7 bits are represent as the magnitude numbers. The first bit from right is a least significant bit (LSB).

Example:

Q1: convert decimal number -125 to binary 


Decimal
8-bits binary number
Notes

Sign
Magnitude

125
0
111 1101
Convert 125 to 7-bits binary

0
000 0010
1st complement (each 0 is changed to 1, each 1 to 0)

0
000 0011
2nd complement (Add +1 to the 1st complement)
-125
1
000 0011
Magnitude number