0% found this document useful (0 votes)
33 views32 pages

Lecture2 Number Systems

Uploaded by

sksmakna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views32 pages

Lecture2 Number Systems

Uploaded by

sksmakna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

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…

14.2 = 1 X 101 + 4 X 100 + 2 X 10-1


Binary Numbers

The binary numbering


system has 2 digits; 0 and 1

The binary numbering


system has a base of 2 with
each position weighted by a
factor of 2

….25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 2-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

There are 3 forms for signed binary numbers


 Sign-magnitude form
 1’s complement form
 2’s complement form
Sign-magnitude
00011001

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

1’s complement=changing all 1s to 0s and all 0s to 1s.


Most popular!!!

2’s complement
Negative number is the 2’s complement of the
corresponding positive number!

+25= 00011001
-25= 11100111

2’s complement= 1’s complement + 1


Example
 Express the decimal number -39 as an 8-bit number
in the sign-magnitude, 1’s complement and 2’s
complement forms.
+39=00100111
 Sign-magnitude
-39=10100111
 1’s complement
-39=11011000
 2’s complement
-39=11011001
Range of signed integer numbers
that can be represented
For unsigned numbers
 8-bit number  1 byte
 28 =256 different numbers can be represented
 16-bits  2 byte
 216 = 65536 different number.
 32-bits  4 byte
 232=4.295x109 different number
For 2’s complement signed numbers
 -(2n-1) to +(2n-1 – 1)
 1 byte  -128 to +127
 2 byte  -32768 to +32767
Arithmetic operations with
signed numbers
Note: Only 2’s complement is covered here !!!
 Addition
00000111(+7) 00001111(-15)
00000100(+4) 11111010(-6)
00001011 (11) 1 00001001(9)

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

Because, the result can not be represented in 8-bit wide!


Arithmetic operations with
signed numbers
 Subtraction : change the sign of subtrahend and add minuend.

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

 Decimal to octal conversion


35910 = 5478

 Binaryto octal conversion


1101012=658
Binary Coded Decimal (BCD)
 8421 code
0 - 0000
1 - 0001 Ex.
2 - 0010
3 - 0011 35=00110101
4 - 0100
5 - 0101 98=10011000
6 - 0110
7 - 0111 170=000101110000
8 - 1000
9 - 1001
BCD
 BCD addition
0011 3
0100 4
0111 7
Digital codes and Parity
 Gray code
 The important feature of the Gray code is that it
exhibits only a single bit change from one code
word to the next in sequence
Binary to Gray code
1+0+1+1+0

1 1 1 0 1

Gray to binary conversion


1 1 0 1 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

 parity bit: total number of 1 is even (even parity)


total number of 1 is odd (odd parity)
(even parity) (odd parity)
ASCII A = 1000001 01000001 11000001
ASCII T = 1010100 11010100 01010100
- helpful in detecting errors during the transmission of information

You might also like