You are on page 1of 48

Computer Number System

Mahit Kumar Paul


Lecturer, Dept. of CSE
RUET,Rajshahi-6204

11/16/2017 1
Data Representation
Computers use digital representation
• Based on a binary system
• uses on/off states to represent 2 digits

Many different types of data.


ALL data (no matter how complex) must be
represented in memory as binary digits (bits).

11/16/2017 2
Why Binary ?

Computers are made of a series of switches

Each switch has two states: ON or OFF

Each state can be represented by a number:


1 for “ON” and 0 for “OFF”

11/16/2017 3
Number system and computer
 Computers store all data as binary digits, but we
may need to convert this to a number system we
are familiar with

Computer programs and data are often


represented (outside the computer) using octal
and hexadecimal number systems because they
are a short hand way of representing binary
numbers

11/16/2017 4
Common Number Systems

11/16/2017 5
Common Number Systems (Contd.)
 Decimal - The Decimal Number System uses base 10. It includes
the digits {0, 1,2,…, 9}.
 Binary - Most modern computer system uses binary logic. The
computer represents values (0,1) using two voltage levels (usually
0V to .8V for logic 0 and +3.3 V to +5V for logic 1). The Binary
Number System uses base 2 includes only the digits 0 and 1
 Octal - The octal numbering system includes eight base digits (0-
7). After 7, the next placeholder to the right begins with a 1. Such
as: 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 ...
 Hexadecimal - The hexadecimal numbering system includes
sixteen base digits (0-F).

11/16/2017 6
Quantities/Counting

11/16/2017 7
Quantities/Counting (Contd.)

11/16/2017 8
Quantities/Counting (Contd.)

11/16/2017 9
Negative Number
 How do we write negative binary numbers?
– Prefix numbers with minus symbol ?
 3 approaches:
– Sign and magnitude
– Ones-complement
– Twos-complement
 All 3 approaches represent positive numbers in
the same way

11/16/2017 10
Sign and Magnitude
• Most significant bit –7 +0
(MSB) is the sign bit –6 1111 0000 +1
1110 0001
0 ≡ positive –5 +2
1101 0010
1 ≡ negative –4
1100 0011
+3

• Remaining bits are – 3 1011 0100 + 4


1010 0101
the number's –2 +5
1001 0110
magnitude –1 1000 0111 +6
–0 +7
• With 8-bit sign magnitude
representation ,we have
(Decimal) Fig: 4-bit Sign magnitude

-127… … -0, +0 … … +127


11/16/2017 11
Problem of Sign and Magnitude
• Problem 1: Two representations of for zero
+0 = 0000 and –0 = 1000
• Problem 2: Arithmetic is difficult
4 + (-3) != 4–3

11/16/2017 12
One’s (1’s) Complement

• Negative number: –1
–0
1111 0000
+0
+1
Bitwise complement of –2 1110 0001 +2
1101 0010
positive number –3
1100 0011
+3

0111 ≡ 710 – 4 1011 0100 + 4


1010 0101
1000 ≡ –710 –5 1001 0110 +5

–6 1000 0111 +6
–7 +7

11/16/2017 13
Why 1’s Complement than Sign
and Magnitude

• Solves the arithmetic problem

11/16/2017 14
Problem of 1’s Complement

• Still have two representations for zero


+0 = 0000
–0 = 1111

11/16/2017 15
Two’s (2’s) Complement
• Negative number: Bitwise
complement plus one –1 0
–2 1111 0000 +1
0111 ≡ 710
–3 1110 0001 +2
1000 1101 0010
–4 +3
1100 0011
1
– 5 1011 0100 + 4
1001 ≡ –710 1010 0101
–6 1001 0110 +5
• Benefits: 1000 0111
–7 +6
– Simplifies arithmetic –8 +7
– Only one zero

11/16/2017 16
Two’s (2’s) Complement (Contd.)

• Solves the arithmetic problem

11/16/2017 17
Conversion among Bases
• The possible conversions-

11/16/2017 18
Binary to Decimal
 Technique
• Multiply each bit by 𝟐𝒏 , where n is the
weight of the bit. The weight is the position of
the bit, starting from 0 on the left of decimal
point and multiply each bit by 𝟐−𝒏 , where n
starts from 1 on the right of decimal point.
• Add the results

11/16/2017 19
Binary to Decimal (Contd.)

 Example

11/16/2017 20
Octal to Decimal
 Technique
• Multiply each bit by 𝟖𝒏 , where n is the
weight of the bit. The weight is the position of
the bit, starting from 0 on the left of decimal
point and multiply each bit by 𝟖−𝒏 , where n
starts from 1 on the right of decimal point.
• Add the results

11/16/2017 21
Octal to Decimal (Contd.)

 Example

11/16/2017 22
Hexadecimal to Decimal
 Technique
• Multiply each bit by 𝟏𝟔𝒏 , where n is the
weight of the bit. The weight is the position of
the bit, starting from 0 on the left of decimal
point and multiply each bit by 𝟏𝟔−𝒏 , where n
starts from 1 on the right of decimal point.
• Add the results

11/16/2017 23
Hexadecimal to Decimal (Contd.)

 Example

11/16/2017 24
Decimal to Binary
 Technique
• Divide by 2, keep track of the remainders
• Organize the remainders as a sequence of bits
denoting the 1st remainder as LSB (Least
Significant Bit) and the last remainder as the
MSB (Most Significant Bit)

11/16/2017 25
Decimal to Binary (Contd.)
 Example : Integer number

11/16/2017 26
Decimal to Binary (Contd.)
 Example : Fractional number

11/16/2017 27
Decimal to Binary (Contd.)
 Example : Fractional number

11/16/2017 28
Octal to Binary
 Technique
• Convert each octal digit to a 3-bit equivalent
binary representation

11/16/2017 29
Octal to Binary (Contd.)
 Example

11/16/2017 30
Hexadecimal to Binary
 Technique
• Convert each hexadecimal digit to a 4-bit
equivalent binary representation

11/16/2017 31
Hexadecimal to Binary (Contd.)
 Example

11/16/2017 32
Decimal to Octal
 Technique
• Divide by 8, keep track of the remainders
• Organize the remainders as a sequence of
digits denoting the 1st remainder as LSB
(Least Significant Bit) and the last remainder
as the MSB (Most Significant Bit)

11/16/2017 33
Decimal to Octal (Contd.)
 Example :

11/16/2017 34
Decimal to Hexadecimal
 Technique
• Divide by 16, keep track of the remainders
• Organize the remainders as a sequence of
digits denoting the 1st remainder as LSB
(Least Significant Bit) and the last remainder
as the MSB (Most Significant Bit)

11/16/2017 35
Decimal to Hexadecimal (Contd.)
 Example :

11/16/2017 36
Binary to Octal
 Technique

• Group bits in threes, starting on right


• Convert to octal digits

11/16/2017 37
Binary to Octal (Contd.)
 Example :

11/16/2017 38
Binary to Hexadecimal
 Technique

• Group bits in fours, starting on right


• Convert to hexadecimal digits

11/16/2017 39
Binary to Hexadecimal (Contd.)
 Example :

11/16/2017 40
Octal to Hexadecimal
 Technique

• Use binary as an intermediary


• Group bits in fours, starting on right
• Convert to hexadecimal digits

11/16/2017 41
Octal to Hexadecimal (Contd.)
 Example :

11/16/2017 42
Hexadecimal to Octal
 Technique

• Use binary as an intermediary


• Group bits in threes, starting on right
• Convert to octal digits

11/16/2017 43
Hexadecimal to Octal (Contd.)
 Example :

11/16/2017 44
Exercise – Convert ...

11/16/2017 45
Motivation
Example: Convert 231.34 to base 7.
Solution:

46

11/16/2017 46
11/16/2017 47
11/16/2017 48

You might also like