You are on page 1of 25

CS221:DigitalDesign

Number System
NumberSystem

Dr.A.Sahu
Dept of Comp. Sc. & Engg.
DeptofComp.Sc.&Engg.
IndianInstituteofTechnologyGuwahati
1

Outline
NumberSystem
Decimal,Binary,Octal,Hex
D i l Bi
O t l H

Conversion(onetoanother)
DecimaltoBinary,Octal,Hex&ViceVersa
Decimal to Binary Octal Hex & Vice Versa
BinarytoHEX&viceversa

Otherrepresentation
Signed,Unsigned,Complement

Operation
Add,Sub,Mul,Div,Mod

Howtohandlerealnumberefficiently?
Float,Double
Float Double
2

What Digit? =>>NumberSystem


WhatDigit?
Number System
FamousNumberSystem:Dec,Rom,Bin
Famous Number System: Dec Rom Bin
DecimalSystem:09
Mayevolves:becausehumanhave10finger
M
l
b
h
h
10 fi

RomanSystem
Mayevolvestomakeeasytolookandfeel
Pre/PostConcept:(IV,V&VI)is(51,5&5+1)

BinarySystem,Others(Oct,Hex)
Onecancutanappleintotwo
pp
3

Significant Digits
SignificantDigits
Binary: 11101101
Binary:11101101
Most significant digit
MostsignificantdigitLeastsignificantdigit
Least significant digit

Decimal:
Decimal:

1063079

Most significant digit


MostsignificantdigitLeastsignificantdigit
Least significant digit

Decimal (base 10)


Decimal(base10)
Uses
Usespositionalrepresentation
positional representation
Eachdigitcorrespondstoapowerof10based
on its position in the number
onitspositioninthenumber
Thepowersof10incrementfrom0,1,2,etc.
asyoumoverighttoleft
i h
l f
1,479=1*103 +4*102 +7*101 +9*100

Binary (base 2)
Binary(base2)
Twodigits:0,1
Tomakethebinarynumbersmore
y
readable,thedigitsareoftenputingroups
of4
1010=1*23 +0*22 +1*21 +0*20
=8+2
= 10
=10
11001001=1*27 +1*26 +1*23 +1*20
=128
128 +64
64 +8
8 +1
1
=201

HowtoEncodeNumbers:Binary
Numbers

Workingwithbinarynumbers

Inbaseten,helpstoknowpowersof10
In base ten helps to know powers of 10
one,ten,hundred,thousand,tenthousand,...

Inbasetwo,helpstoknowpowersof2
I b
t
h l t k
f2
one,two,four,eight,sixteen,thirtytwo,sixty
f
four,onehundredtwentyeight
h d dt
t i ht
Countupbypowersoftwo
29

28

27

26

25

24

23

22

21

20

512 256 128 64 32

16

Octal (base 8)
Octal(base8)
Shorter&easiertoreadthanbinary
8digits:0,1,2,3,4,5,6,7,
Octalnumbers
Octal numbers

1368 =1*82 +3*81 +6*80


=1*64+3*8+6*1
1 * 64 3 * 8 6 * 1
=9410

Hexadecimal (base 16)


Hexadecimal(base16)
Shorter&easiertoreadthanbinary
16digits:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
0x
0x oftenprecedeshexadecimalnumbers
often precedes hexadecimal numbers

0x123=1*162 +2*161 +3*160


=1*256+2*16+3*1
1 * 256 2 * 16 3 * 1
=256+32+3
=291

Counting

Decimal

Binary

Octal

Hexadecimal

00000

00001

00010

00011

00100

00101

00110

00111

01000

10

01001

11

10

01010

12

11

01011

13

12

01100

14

13

01101

15

14

01110

16

15

01111

17

16

10000

20

10

10

Fractional Number
FractionalNumber
Point:DecimalPoint,BinaryPoint,Hexadecimal
point
Decimal
247.75=2x102+4x101+7x100+7x101+5x102

Binary
10.101=1x21+0x20+1x21+0x22+1x23

Hexadecimal
6A.7D=6x161+10x160+7x161+Dx162

Converting To and From Decimal


ConvertingToandFromDecimal

Successive
Division
Weighted
Multiplication

Octal8
01234567

Decimal10
0123456789

Weighted
M lti li ti
Successive Multiplication
Division
Successive Weighted
Di i i
Division
M lti li ti
Multiplication

Hexadecimal16

Binary2

0123456789ABCDEF

01

12

Decimal
Binary
DecimalBinary
Successive
Division

a)) Dividethedecimalnumberby2;theremainderistheLSBofthebinary
y ;
y
number.
b) Ifthequotationiszero,theconversioniscomplete.Otherwiserepeatstep
(a)usingthequotationasthedecimalnumber.Thenewremainderisthe
( )
g
q
nextmostsignificantbitofthebinary number.
Weighted
Multiplication

a) Multiplyeachbitofthebinary numberbyitscorrespondingbit
weightingfactor(i.e.,Bit020=1;Bit121=2;Bit222=4;etc).
b) Sumupalloftheproductsinstep (a)togetthedecimalnumber.

DecimaltoBinary:SubtractionMethod
y
Goal
Goodforhuman
Getthebinaryweightsto
adduptothedecimal
dd
t th d i l
quantity

Desired decimal number: 12


Desireddecimalnumber:12
32 16

=32

1
32 16

toomuch
a

=8
4

ok,keepgoing

=8+4=12
2

0 1 1 0 0

32 16

toomuch

=16

0 1 1

32 16

Workfromlefttoright
32 16 8
(Righttoleft mayfillin1s
0 0 1
thatshouldnthavebeen
32 16 8
there tryit).
0

DONE

answer

DecimaltoBinary:DivisionMethod
y
Goodforcomputer:Dividedecimalnumberby2and
insertremainderintonewbinarynumber.
y
Continuedividingquotientby2untilthequotientis0.

Example:Convertdecimalnumber12tobinary
12div2=(Quo=6,Rem=0)LSB
6div2=(Quo=3,Rem=0)
(
)
3div2=(Quo=1,Rem=1)
1 div 2 = ( Quo=0 Rem=1) MSB
1div2=(Quo=0,Rem=1)MSB

1210=1100
1 1 00 22

ConversionProcessDecimalBaseN
Successive
Division

a)) DividethedecimalnumberbyN;theremainderistheLSBoftheANY
y ;
BASENumber.
b) Ifthequotientiszero,theconversioniscomplete.Otherwiserepeat
step(a)usingthequotientasthedecimalnumber.Thenewremainder
p( )
g
q
isthenextmostsignificantbitoftheANYBASEnumber.
Weighted
Multiplication

a) MultiplyeachbitoftheANYBASEnumberbyitscorrespondingbit
weightingfactor(i.e.,Bit0N0;Bit1N1;Bit2N2;etc).
b) Sumupalloftheproductsinstep(a)togetthedecimalnumber.

Decimal Octal Conversion


DecimalOctalConversion
TheProcess:SuccessiveDivision
Divide number by8; RistheLSBoftheoctal number
WhileQis0
UsingtheQasthedecimalnumber.
NewremainderisMSBoftheoctal number.
11
8 94

r = 6 LSB

1
8 11

r =3

0
8 1

r = 1 MSB

9410 = 1368

17

Decimal Hexadecimal Conversion


DecimalHexadecimalConversion
TheProcess:SuccessiveDivision
Dividenumber by16;RistheLSBofthehex
number
WhileQis0
UsingtheQasthedecimalnumber.
NewremainderisMSBofthehex number.
5
16 94
0
16 5

r = E LSB
S

9410 = 5E16
r = 5 MSB

Example: Hex Octal


Example:HexOctal
Example:
C
Convertthehexadecimalnumber5A
h h d i l
b 5AH intoitsoctalequivalent.
i
i
l
i l
Solution:
Firstconvertthehexadecimalnumberintoitsdecimalequivalent,then
First
convert the hexadecimal number into its decimal equivalent then
convertthedecimalnumberintoitsoctalequivalent.

16

16

16

80

10

= 9010
5AH =1328

11
8 90

r = 2 LSB

1
8 11

r =3

0
8 1

r = 1 MSB

19

Example: Octal Binary


Example:OctalBinary
Example:
Convert the octal number 1328 intoitsbinaryequivalent.
Converttheoctalnumber132
into its binary equivalent
Solution:
Firstconverttheoctalnumberintoitsdecimalequivalent,thenconvertthe
d
decimalnumberintoitsbinaryequivalent.
l
b
b
l

82

81

80

64

2
2

64 + 24 +

= 9010

2
2
2

45
90 r = 0 LSB
22
45 r = 1
11
22 r = 0
5
11 r = 1
2
5 r =1
1
2 r =0
0
1
r = 1 MSB

1328 =10110102

20

Binary Octal Hex Shortcut


BinaryOctalHexShortcut
Relation
Binary,octal,andhexnumbersystems
Bi
l dh
b
Allpowersoftwo
Exploit(ThisRelation)
Makeconversioneasier.

21

Substitution Code
SubstitutionCode
Convert010101101010111001101010
Convert
0101011010101110011010102 tohexusing
to hex using
the4bitsubstitutioncode:

0101 01101010111001101010

56AE6A16

Substitution Code
SubstitutionCode
Substitutioncodecanalsobeusedtoconvertbinaryto
octalbyusing3bitgroupings:
2

010101 101010111 001101010

255271528

Other Representation
OtherRepresentation
Signed&UnsignedNumber
Signednumberlastbit(oneMSB)issignedbit
Si d
b l bi (
MSB) i i d bi
Assume:8bitnumber
Unsigned12:00001100
Signed+12:00001100
Signed12:10001100
Complementnumber
p
Unsignedbinary12=00001100
1ssComplementof12=1111
1
Complement of 12 = 1111 0011
24

Thanks

25

You might also like