Lecture2 Number Systems
Lecture2 Number Systems
MANTIK DEVRELERİ
Yard.Doç.Dr. Mutlu BOZTEPE
Decimal Numbering System
The decimal numbering system has 10 digits 0 through 9
The decimal numbering system has a base of 10 with each
position weighted by a factor of 10
….105 104 103 102 101 100. 10-1 10-2 10-3 10-4 10-5…
10111 = 1 X 24 +0 X 23 +1 X 22 +1 X 21 + 1 X 20
Decimal-to-Binary
Conversion
Sum-of-weight method
Binary weights
256 128 64 32 16 8 4 2 1
357 = 256 + 64 + 32 + 4 + 1 101100101
Binary weights
1024 512 256 128 64 32 16 8 4 2 1
1937 = 1024 + 512 + 256 + 128 + 16 + 1 11110010001
Decimal-to-Binary Conversion
Repeated division-by-2 method
Converting Decimal fractions to Binary
Using Sum-of-weights
Binary weights
64 32 16 8 4 2 1 .5 .25 .125 .0625
95.6875 = 64 + 16 + 8 + 4 + 2 + 1 + .5 + .125 + .0625
1011111.1011
Repeated division by 2 yields the whole number while
repeated multiplication by 2 of the fraction yields the
binary fraction
Binary arithmetic
Binary Addition Binary subtraction
0 + 0 = 0 Sum of 0 with a carry of 0 0-0=0
0 + 1 = 1 Sum of 1 with a carry of 0 1-1=0
1 + 0 = 1 Sum of 1 with a carry of 0 1-0=1
1 + 1 = 10 Sum of 1 with a carry of 1 0 - 1 = 1 (with a borrow of 1)
11001
1011
+ 1101
- 111
100110
100
Binary subtraction
Binary arithmetic
Binary Multiplication
0 X 0 = 0
0 X 1 = 0
1 X 0 = 0 100110
1 X 1 = 1 x 101
100110
000000
+ 100110
10111110
Signed Numbers
Sign bit
The left most bit in a signed binary number is sign bit.
0 for positive numbers
1 for negative numbers
Sign magnitude
-25 = 10011001
+25= 00011001
1’s complement form
Negative number is the 1’s complement of the
corresponding positive number!
+25= 00011001
-25= 11100110
2’s complement
Negative number is the 2’s complement of the
corresponding positive number!
+25= 00011001
-25= 11100111
00010000(16) 11111011(-5)
11101000(-24) 11110111(-9)
11111000(-8) 1 11110010(-14)
Discard carry
2’s
complement
Arithmetic operations with
signed numbers
Overflow condition
01111101 126
00111010 58
10110111 183
magnitude incorrect
Sign incorrect
00001000 +8
- 00000011 +3
2’s complement of +3
00001000 +8
11111101 -3
1 00000101 +5
Arithmetic operations with
signed numbers
Multiplication :
Step1: Determine the sign of the result( This determines what the
sign of the product will be)
Step2: Change negative numbers to positive by 2’s complement
Step3: Multiply them by partial product method
Step4: If the sign of the result is negative, take 2’s complement of
the result. (note that the bit wide of result has 2 times more than
numbers.
Ex.
Note that: result is 16-bit (2 byte)
Hexadecimal numbers
Hexadecimal numbers
Counting in hexadecimal
…10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1F,20…
Binary-to-hexadecimal conversion
1100101001010111=CA57
C A 5 7
Hexadecimal to binary conversion
10A4=0001000010100100
Hexadecimal to decimal conversion
1C16 =2810
Decimal to hexadecimal conversion
65010 = 28A16
Hexadecimal numbers
Hexadecimal addition
23+16=39 58+22=7A
Hexadecimal 2’s
complement
Method 1
Method 2
Method 3
Octal numbers
Octal numbers
Octalto decimal conversion
23748=127610
1 1 1 0 1
1 0 0 1 0
ASCII code
Parity Method for error Detection
ASCII is a 7-bit code + 1 bit => 8-bit (1 byte)
\---- used for specific purpose