You are on page 1of 44

Chapter 3

Data Representation In Computers


Units of Data Representation
When data is stored, processed, or communicated within the computer system, it is
“packed” in units.
Arranged from the smallest to the largest, the units are called bits, bytes, & words.
Bits: is abbreviated for binary digit, the smallest unit of information that can be
stored and manipulated by a computer.
A bit is represented by the numbers 1, & 0, which correspond to the states on & off,
true & false, or yes & no.
Bytes: is the collection of 8 bit.
Is the basic unit of information in a computer’s memory.
1 bit has 2 states, there are 8 bits in a byte. The possible combination is 256(2 ).
8

These combination can provides enough possible patterns to represent the entire
alphabet(A-Z/a-z), numeric digits(0,1,2,…,9), special characters(!, ?, *, …)
Bytes are calculated by raising the number 2 to various power.
Words
Bytes are combined into groups of 1 to 8 bytes called words.
Words refer to the number of bits that a computer process at once.
Typically word lengths are 8 bits, 16 bits, 32 bits & 64 bits.

June 15, 2023 Admas University 2


Basic Units of Measurement
• BIT is a unit of information equivalent to the result of a choice
between only 2 possible alternatives in the binary number
system.
• BYTE is a sequence of 8 bits (enough to represent one character
of alphanumeric data) processed as a single unit for
information.
• A byte can be used to represent a single character, which can be:
• A letter
• A number
• A special character or symbol, or
• A space

Why Binary?
 ‘Why do we go for binary numbers instead of decimal
numbers?’ The reasons are as follows:
 The 1 s t reason is that the electronic & electrical
components, by their very nature, operate in a binary
mode.
Information is handled in the computer by
electronic/electrical components such as transistors,
semiconductors, wires, etc all of which can only indicate
2 states or conditions – on(1) or off(0).
 Tra n s is t o rs a re eit h er c o n d u c t in g ( 1 ) o r n o n -
conducting (0); a voltage is present (1) or absent (0) in
wire.

June 15, 2023 Admas University 5


 The binary number system, which has only two digits (0&1), is
most suitable for expressing the two possible states.
 The second reason is that the computer circuits only have to
handle two binary digits rather than ten decimal digits.
 This greatly simplifies the internal circuit design of computers,
resulting in less expensive & more reliable circuits.
 Finally, the binary system is used because everything that can
be done in decimal number system (addition, subtraction,
division & multiplication) can also be done in binary number
system.

Concept of Numbering System
 Every computer stores numbers, letters, & other special
characters in a coded form.
 Before going to the details of these codes, it is essential
to have a basic understanding of the number system.
 So the goal of this topic is to familiarize you with the
basic fundamentals of number system.
 There are various number systems
Decimal
Binary
Octal
Hexadecimal

June 15, 2023 Admas University 7
The Decimal Number System
• Uses number 10 as its base or radix.
• Base is def ined as the total number of digits available in the
number system
• Has 10 symbol or digits (0, 1, 2, 3, 4, 5, 6, 7, 8,9 )
• The largest single digit is 9(one less than the base)
• Uses positional notation(units, tens, hundreds, thousands,
…) for numbers greater than numbers 9

June 15, 2023 Admas University 8



For example, the decimal number 4 8 5 6 is equal to:

(4 * 103) + (8*102) + (5 * 101) + (6 * 100)

Thousands Hundreds Tens Ones



The weight of the nth digit of the number from the left of the decimal point is
equal to:
nth digit * 10n-1
June 15, 2023 Admas University 9
The weight of the nth digit of the number from the right of the decimal point is
Binary number System
 The base or radix is 2
 Has two symbols(0&1)
 The largest single digit is 1(one less than the base)
 Each position in binary number represents a power of the base (2).
 The right most position is the units (2 ) position, the second is the
0

2`s(2 ) position, & proceeding in this way we have 4`s(2 ) position,


1 2

8`s(2 ) position, 16`s (2 ) position, & so on.


3 4

June 15, 2023 Admas University 10


Example: Binary number 10101 written as ( 101012
= (1*24) + (0*23) + (1*22) + (0*21) + (1*20)
= 16 + 0 + 4 + 0 + 1
= 21
Octal Number System
 The base is 8
 There are only 8 digits: 0,1,2,3,4,5,6,7
 The largest single digit is 7
 Each position on octal number represents a power of
the base(8).

June 15, 2023 Admas University 11


Hexadecimal Number System
 The base is 16
 Has 16 single-character digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
(The letters A to F represent numbers 10 to 15)
 Each position in the hexadecimal system represents a power of
the base(16).

June 15, 2023 Admas University 12


Conversion Among Bases
• The Possibilities

Decimal Octal

Binary Hexadecimal
Converting from One Number System to Another

• Converting to Decimal from another Base


Steps
• Determine the positional value of each digit & multiply the
obtained positional values by the digits in the corresponding
position.
• Sum the products calculated in step 1. The total is the
equivalent value in decimal

June 15, 2023 Admas University 14


Converting from Decimal to Another Base (Division Remainder Technique)

Steps
 Step 1. Divide the decimal number to be converted by the value of
the new base.
 Step 2 Record the remainder from step 1 as the rightmost digit
(least significant digit) of the 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)
 Repeat step 3 & 4, recording remainder from right to left until
the quotient become zero in step 3.
 Note that the last remainder thus obtained will be the most
significant digit of the new base number.
June 15, 2023 Admas University 15
Converting a Decimal Fraction to a fractional in
base B
Steps
 Step 1: Multiply the given decimal fraction by the base B.
 Step 2: Repeat step 1 using the multiplicant at each step
the remaining fraction part is identically zero, or until as
many digit as desired have been generated.
 The successive integral parts are the successive digits of
the number in base B starting from the most signif ic ant
end.

June 15, 2023 Admas University 16


Conversion of non-decimal base to another non-decimal base

• Step 1: Convert the original number to a decimal


number (base 10)
• Step 2: Convert the decimal number so obtained to
the new base number.

June 15, 2023 Admas University 17


Binary to Decimal
Example
Decimal to Binary
Example
Octal to Decimal
• Technique
Multiply each bit by 8n , wheren is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
• Technique
Multiply each bit by 16n , wheren is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12
B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Octal to Binary
• Technique
Convert each octal digit to a 3-bit equivalent binary representation

Example 7058 = ?2 7 0 5


111 000 101

7058 = 1110001012
Hexadecimal to Binary
• Technique
Convert each hexadecimal digit to a 4-bit equivalent binary
representation

Decimal to Octal
• Technique
Divide by 8
Keep track of the remainder
Decimal to Hexadecimal
• Technique
Divide by 16
Keep track of the remainder
Binary to Octal
• Technique
Group bits in threes, starting on right
Convert to octal digits

Binary to Hexadecimal
• Technique
Group bits in fours, starting on right
Convert to hexadecimal digits
Octal to Hexadecimal
• Technique
Use binary as an intermediary

Hexadecimal to Octal
• Technique
Use binary as an intermediary
Exercise – Fill the blank with Converted
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don’t use a calculator!


Arithmetic System
• During school days, arithmetic was restricted only to decimal
number system.
• However, in computer, we require arithmetic on other number
systems such as binary, octal and hexadecimal.
• Everything that is stored in or manipulated by the computer is a
number.
• The computer understands the numbers 1 and 0.
• The basic arithmetic operations of the binary number system
are: Addition and subtraction.
Binary Addition
• Binary addition is carried out in the same way as the decimal
addition is performed. There are four outcomes or rules of the
binary addition. These are shown below:
Input Output
X Y Sum (S) Carry (R)
0 0 0 0
0 1 1 0

1 0 1 0
1 1 0 1
• Example: Add the binary numbers 1111 and 1010.
1 1 1 1
+ 1 0 1 0
• 1 1 0 0 1 Thus the binary sum is (11001) 2.


Binary Addition (2 of 2)
• Two n -bit values
Add individual bits
Propagate carries
E.g.,

1 1
10101 21
+ 11001 + 25
101110 46
Binary Subtraction
• Subtraction is generally simple in comparison to addition since
only two numbers are involved.
• In binary subtraction the problem ‘borrow’ is similar to that in
decimal.
• If the subtracted bit is equal to or smaller than the minuend
bit, then perform subtraction, otherwise borrow one(the base 2)
from its left most neighbor.
• Find the binary difference of (1101-1011).



Binary Multiplication
• Binary, two n -bit values
• As with decimal values
• E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
Coding Methods
• Code is a group of symbols
• Code is a systematic use of a given set of symbols for representing
information
• Code: A set of n-bit strings in which different bit strings represent
different numbers or other things.
• Weighted code :- Each positions are represent specific weight
 Eg. 8 4 2 1 ,2 4 2 1
• Non-weighted code:- non positional codes
 Eg ex-3,GrayCode
• Sequential codes:- Each succeeding code is one binary numbers greater than
the preceding code. Ex 8 4 2 1 , ex-3
• Alphanumerical codes:-we can represent number, characters, symbol and
small Instruction Ex. ASCII

4-Bit Binary Coded Decimal (BCD)
Systems
• The 4-bit BCD system is usually employed by the computer
systems to represent and process numerical data only.
To represent 10 decimal digits(0000:0 ….1001: 9), at
least need 4 bits.
• (Each decimal number ((base 10 i.e 0,1,2…9)) Represent by a
4 bit Binary binary (0,1) number )
• In the 4-bit BCD system, each digit of the decimal number is
Represented to its corresponding 4-bit binary sequence.
• The two most popular 4-bit BCD systems are:
 Weighted 4-bit BCD code
 Excess-3 (XS-3) BCD code


Weighted 4-Bit BCD Code
• The weighted 4-bit BCD code is more commonly known as 8421
weighted code (pronounce eight , four , two, one ).
8421 and BCD codes are the same
• It is called weighted code because it encodes the decimal
system into binary system by using the concept of positional
weighting into consideration.
• In this code, each decimal digit is encoded into its 4-bit
binary number in which the bits from left to right have the
weights 8, 4, 2, and 1, respectively.

Weighted 4-Bit BCD Code








 Apart from 8421, some other weighted BCD codes are 4221,
2421 and 5211


Weighted 4-Bit BCD Code
• Example :- Represent the decimal number 5327 in 8421 BCD
code.
 The corresponding 4-bit 8421 BCD representation of decimal digit 5 is
0101
 The corresponding 4-bit 8421 BCD representation of decimal digit 3 is
0011
 The corresponding 4-bit 8421 BCD representation of decimal digit 2 is
0010
 The corresponding 4-bit 8421 BCD representation of decimal digit 7 is
0111
 Therefore, the 8421 BCD representation of decimal number 5327 is
0101001100100111.

Binary Coded Decimal (BCD)
Example Represent the decimal number 938 in 8421 BCD code.


8 4 2 1 8 4 2 1 8 4 2 1
1 0 0 1 0 0 1 1 1 0 0 0
8 + 0 + 0 + 1 0 + 0 + 2 + 1 8 + 0 + 0 + 0
9 3 8

• Therefore 1001 0011 1000 in BCD = 938 in denary.
Reading Assignment

 ASCII-7 and ASCII-8

 UNICODE

 One’s and two’s complement

 Representing floating point by using binary system.

You might also like