Computer Codes
Computer Codes
2
Number System
• Mainly there are two types of number
systems
• Non-Positional Number System
• Use fingers for counting. Use stones
• Does the direction matter?
• Positional Number System
• Position matters
Non-positional Number System
• Use symbols such as I for 1, II for 2, III for 3, etc
642 is 6 * 102 + 4 * 10 + 2 * 1
Positional Notation
• What if 642 has a base of 13?
(1011)2 = 1 * 23 + 0 * 22 + 1 * 21 +
1 * 20
(A12)16 = A * 162 + 1 * 161 + 2 *
160
Binary to Hexa and Hexa to Binary?
(BC11)16 = ( )2
(1110011101)2 = ( )16
How many numbers can be represented
using different number of bits?
1 bit 2 bits 3 bits 4 bits
Computer Arithmetic
Binary Addition
oExample
Binary Addition
oExample
Binary Subtraction
oExample
Binary Subtraction
oExample
Issues in Binary Subtraction
+53 = 00110101
-53 = 11001010
+53 = 00110101
-53 = 11001011
Issues in Binary Subtraction
o 2’s Complement
o First of all 2's complement of the subtrahend (In a-b,
b is subtrahend) is found
o Then it is added to minuend (In a-b, a is minuend)
o If the final carry over of the sum is 1, it is dropped
and the result is positive
o If there is no carry, the 2's complement of the sum
will be the result and it is negative
Signed-magnitude
Two’s Complement for adding +3
number for adding two
and -3
number (+3 and -3) using
4 bits representation