3.number System

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

CSE-212

Number System
Contents
• What is number system
• Different types of number systems
• Conversions of number system
Number system
• When we type some letters or words, the computer translates
them in numbers as computers can understand only numbers.
A computer can understand positional number system where
there are only a few digits and these digits represent different
values depending on the position they occupy in the number.

A value of each digit in a number can be determined using


• The digit.
• The position of the digit in the number.
• The base of the number system.
Base & Positional number system
What is base?
• Base: The total number of primary digits available in that
number system. Such as base of decimal system is 10 as it
uses digits from 0 to 9, base of binary system is 2 etc.

What is Positional number system?


• Each position represents a specific power of the base(10).
For example, the decimal number 1234 consists of the digit
4 in units position, 3 in the tens position, 2 in the hundreds
position & 1 in the thousands position.
Number system
• Decimal Number System
Base 10. Digits used : 0 to 9.
• Binary Number System
Base 2. Digits used : 0, 1.
• Octal Number System
Base 8. Digits used : 0 to 7.
• Hexa Decimal Number System
Base 16. Digits used : 0 to 9, Letters used : A- F.
Decimal number system
• The number system that we use in our day-to-day life is the
decimal number system. In decimal number system, the
successive positions to the left of the decimal point represent
units, tens, hundreds, thousands and so on.
• For example, 8253 can be expressed as,
8253=8*103+2*102+5*101+3*100
=8*1000+2*100+5*10+3*1
=8000+200+50+3
• Any fractional point can also be expressed as,
837.526=8*102+3*101+7*100+5*10-1+2*10-2+6*10-3
=8*100+3*10+7*1+5*0.1+2*0.01+6*0.001
=800+30+7+0.5+0.02+0.006
Where, 10-1=0.1, 10-2=0.01, 10-3=0.001
Binary number system
Characteristics of Binary number system are as follows:
• Uses two digits, 0 and 1.
• Also called base 2 number system
• Each position in a binary number represents a power of the
base (2). Example 20
• Examples are : 10001, 11101001, 110 etc.

Peoples do not use this system normally. The idea of this was
first given by Libnitz at seventeenth century. At 1854,
Mathematician Bool has introduced binary number system
and he also described algebras of binary system. That why
algebra related to binary system is called Boolean Algebra.
Binary number system

Decimal Binary Binary place Decimal


0 0 values Values
1 1 2-4 0.0625
2 10 2-3 0.125
3 11 2-2 0.25
4 100 2-1 0.5
5 101 20 1
. . 21 2
. . 22 4
Octal system
Characteristics of octal number system are as follows:
• Uses eight digits, 0,1,2,3,4,5,6,7.
• Also called base 8 number system
• Each position in an octal number represents a power of the
base (8). Example 80.
• Examples are : 123, 2567,723564.

Here the biggest number is 7. All numbers in Octal system is


generated using numbers 0 to 7. Such as 457 is an octal
number.
King of Sweden Charles 7th introduced this number system. UNIX
system uses octal system.
Octal system
Octal digit Decimal Binary Octal place Decimal values
values equivalent values
0 0 000
8-3 1/512=0.001953
1 1 001
125
2 2 010
8-2 1/64=0.0015625
3 3 011
4 4 100 8-1 1/8=0.125
5 5 101 80 1
6 6 110 81 8
7 7 111 82 64
83 512
84 4096
Hexadecimal number system
Characteristics of hexadecimal number system are as follows:
• Uses 10 digits and 6 letters, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
• Letters represents numbers starting from 10. A = 10. B = 11, C
= 12, D = 13, E = 14, F = 15.
• Also called base 16 number system
• Each position in a hexadecimal number represents a power of
the base (16). Example 160
• Example : 16, 1A2, EEEE, 25C.A2 etc.
Hexadecimal number system

Hexa decimal Decimal values Binary values


digits

0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
Hexadecimal number system
Hexa Decimal Binary Hexadecimal Decimal value
decimal values values value
digits
16-3 1/4096=0.000244
8 8 1000 140625
9 9 1001 16-2 1/256=0.0039062
5
A 10 1010
16-1 1/16
B 11 1011
16-0 0.0625
C 12 1100
161 1
D 13 1101
E 14 1110
162 16

F 15 1111
Conversion
• Decimal to Other Base System
• Other Base System to Decimal
• Other Base System to Non-Decimal
Decimal to Other Base System
• Step 1 - Divide the decimal number to be converted by the value of the
new base.
• Step 2 - Get the remainder from Step 1 as the rightmost digit (least
significant digit) of new base number.
• Step 3 - Divide the quotient of the previous divide by the new base.
• Step 4 - Record the remainder from Step 3 as the next digit (to the left) of
the new base number.
• Example Operation result remainder
• Decimal Number : 2910 29/2 14 1
• Calculating Binary Equivalent: 14/2 7 0
2910=111012 7/2 3 1
3/2 1 1
1/2 0 1
Other systems to decimal
• Step 1 - Determine the column (positional) value of each digit (this
depends on the position of the digit and the base of the number system).
• Step 2 - Multiply the obtained column values (in Step 1) by the digits in
the corresponding columns.
• Step 3 - Sum the products calculated in Step 2. The total is the equivalent
value in decimal.
Step Binary Decimal
• Example
1 111012 ((1 x 24) + (1
• Binary Number : 111012 x 23) + (1 x
• Calculating Decimal Equivalent: 22) + (0 x 21)
+ (1 x 20))10
• Decimal number : 2910
2 111012 (16 + 8 + 4 +
0 + 1)10
3 111012 2910
Conversion between other system
• Step 1 - Convert the original number to a decimal (base 10) number
• Step 2 - Convert the number so obtained to the new base number.
• Example: Octal Number : 258
Calculating Binary Equivalent:

Octal Decimal

1 0
25 2*8 +5*8

25 16+5

25 21

Binary value of 1810 is : 100102


Binary to octal and hexadecimal
To octal:
• Step 1 - Divide the binary digits into groups of three (starting from the
right).
• Step 2 - Convert each group of three binary digits to one octal digit.
• Example
• Binary Number : 101012
• Calculating octal equivalent: 25
Binary to octal and hexadecimal
To hexadecimal:
• Step 1 - Divide the binary digits into groups of four (starting from the
right).
• Step 2 - Convert each group of four binary digits to one hexadecimal
symbol.
• Example
• Binary Number : 101012
• Calculating hexadecimal Equivalent: 15
Octal to Hexadecimal and vice versa

• It is not possible to convert an octal number


directly to hexadecimal number and vice
versa.
• To convert an octal to a hexadecimal we need
to transform it in a intermediary form as
decimal or binary form.
• Then we can convert the intermediary form to
required format.
Binary operations
4 types of operation performs:
• Addition
• Subtraction
• Multiplication
• Division

03/21/2023 21
Binary Addition
It is a key for binary subtraction, multiplication, division. There are four rules of
binary addition.
The addition of two binary numbers follows three steps:
• Step 1: Add the first column
• Step 2: Record the unit digit of the column sum, if the sum exceeds “1”,
carry 1 goes to the next column
• Step 3: If there are additional columns or if there is a carry from step 2 ,
add the next column and repeat step 2, otherwise stop.
The facts needed for binary addition:

03/21/2023 22
Binary Addition
• EXAMPLE - ADDITION

03/21/2023 23
Binary Subtraction
Subtraction and Borrow, these two words will be used very frequently for the
binary subtraction. There are four rules of binary subtraction.
Subtraction can be performed by following two steps:
• Step 1: If the lower(Subtrahend) digit is greater than the upper(minuend)
digit, borrow from the next column to the left.
• Step 2: Subtract the lower value from the upper value
The facts needed for binary subtraction:

Case A–B Subtraction Borrow

1 0–0 0 0

2 1–1 0 0

3 1–0 1 0

4 0–1 1 1

03/21/2023 24
Binary Subtraction
• EXAMPLE - SUBTRACTION

03/21/2023 25
Binary Multiplication
Binary multiplication is similar to decimal multiplication. It is
simpler than decimal multiplication because only 0s and 1s are
involved. There are four rules of binary multiplication.

03/21/2023 26
Binary Multiplication

03/21/2023 27
Binary Division
Binary division is similar to decimal division. It is called as the long
division procedure.
EXAMPLE - DIVISION

03/21/2023 28
Complements
• On binary representation, we saw how nonnegative
integer values like, 97 are represented in memory.
What if, instead of having 97, we had -97? We need a
way to represent negative integers.
• Complements are used in the digital computers in
order to simplify the subtraction operation.
• The two types of complements for the binary system
are 2's complement and 1's complement.

03/21/2023 29
Complements
Once
• Plus sign before a number to say that this is a positive
number and minus sign to say that this is a negative
number.
– Sign bit: 0 means positive number
– Sign bit: 1 means negative number
But this is not used anymore and complement system is
being used today.

03/21/2023 30
Complements
An unfortunate feature of Sign-Value representation is
that there are two ways of representing the value zero:
all bits set to zero, and all bits except the sign bit set to
zero.

03/21/2023 31
1's complement

• The 1's complement of a number is found by changing all 1's


to 0's and all 0's to 1's. This is called as taking complement or
1's complement. Example of 1's Complement is as follows.

03/21/2023 32
Disadvantages of 1's complement

03/21/2023 33
2's complement
• The 2's complement of binary number is obtained by adding 1 to
the Least Significant Bit (LSB) of 1's complement of the number.
• 2's complement = 1's complement + 1
• Example of 2's Complement is as follows.

03/21/2023 34
2’s Complement
• Binary subtraction can be performed by
adding two’s complement:
• -9+4 By binary complement
Two’s complement of 9: 10111 (1st bit is sign bit)
Binary number for 4: 00100 (1st bit is sign bit)
By addition 11011 (difference)

03/21/2023 35
Advantages of 2's complement
1. It lessens circuit
2. It increases operability
3. It lessens complexity
4. Lessens weight
5. Speed up processing
6. Reduces cost

03/21/2023 36
Numerical data representation
A binary digit or bit can represent only two symbols as it has
only two states '0' or '1'. But this is not enough for
communication between two computers because there we
need many more symbols for communication. These symbols
are required to represent 26 alphabets with capital and small
letters, numbers from 0 to 9, punctuation marks and other
symbols. For this there are

• BCD code
• Alphanumeric code
• Unicode

03/21/2023 37
BCD
Binary Coded Decimal(BCD):
• To encode Decimal digits Binary
• Requires 4 bits
• Weighted codes
• From left to right weights 8,4,2,1
• BCD representation of 469 is
4 6 9
0100 0110 1001

03/21/2023 38
BCD

03/21/2023 39
Alphanumeric codes
• ASCII:
– American Standard Code For Information Interchange.
– 8 bit codes
– used to represent characters and digits.
– First bit is used as parity bit, next 3 bits used as zone bit and
last 4bits used as numeric bits
• EBCDIC:
– Extended Binary coded Decimal Interchange Code.
– Developed by IBM.
– 8- bit representation.
– First 4 bits used as zone bit and last 4bits used as numeric bits

03/21/2023 40
Unicode
• 16- bit code
• Designed to support different international
languages(Like Bangla, Hindi, Chinese etc.) as
those languages have too many characters to
be represented by eight bit ASCII & EBCDIC
codes.
• Developed by Unicode Inc.

03/21/2023 41
EBCDIC vs. ASCII
1. EBCDIC uses 8 bits while ASCII uses 7 before it was
extended.
2. EBCDIC contained more characters than ASCII.
3. ASCII uses a linear ordering of letters while EBCDIC
does not.
4. Different versions of ASCII are mostly compatible
while different versions of EBCDIC are not.
5. EBCDIC isn’t compatible with modern encodings
while ASCII is.

03/21/2023 42
ASCII vs. Unicode
1. ASCII uses an 8-bit encoding while Unicode uses 16 bit encoding.
2. Unicode is standardized while ASCII isn’t.
3. Unicode represents most written languages in the world while
ASCII does not.
4. ASCII has its equivalent within Unicode.
5. ASCII means American Standard Code for Information
Interchange & UniCode means Universal Code
6. ASCII can represents 256 symbols and UniCode represents 65536
symbols.
7. ASCII requires less memory and Unicode requires much more
memory than ASCII

03/21/2023 43
ASCII vs. BCD
1. ASCII uses an 8-bit encoding while BCD uses 4 bit
encoding.
2. ASCII means American Standard Code for
Information Interchange & BCD means Binary
Coded Decimal
3. ASCII can represents 256 different symbols and BCD
represents 16 different symbols.
4. ASCII is used more than BCD

03/21/2023 44

You might also like