0% found this document useful (0 votes)
12 views

Chapter 3 Part I Data Representation

Uploaded by

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

Chapter 3 Part I Data Representation

Uploaded by

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

Chapter 3 Part I

Data Representation In Computers

Compiled By: Kassahun T.

April 18, 2024 unity University 1


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(28).
➢ 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.
April 18, 2024 unity 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
April 18, 2024 unity University 3
April 18, 2024 unity University 4
Why Binary?
➢‘Why do we go for binary numbers instead of
decimal numbers?’ The reasons are as follows:
➢The 1st 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).
➢Transistors are either conducting (1) or non-
conducting (0); a voltage is present (1) or absent (0)
in wire.
April 18, 2024 unity 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.

April 18, 2024 unity University 6


Numbering System
➢A number system is a set of symbols used for counting. The
number systems which are of a particular interest in information
technology are Decimal, binary, octal and hexadecimal number
system. Number systems are basically of two types: non
positional and positional
➢ Non-positional number system is a number system in which
case each symbol represents the same value regardless of its
position in the number and the symbols are added to find out the
value of particular number.
➢Example: Counting of fingers, stones, sticks etc.
➢Positional number system is a number system in which a
value of a number depends on the position of the digits. The
number 123 has a different value than the number 321, although
the same digits are used in both numbers.
April 18, 2024 unity University 7
Numbering System
➢ The value of each digit in such a number is determined by three
considerations:
➢1 The digit itself
➢2 The position of the number
➢3 The base of the number system
➢For the purpose of understanding how data are represented,
stored and processed in computer, we will discuss Number
Systems that are commonly used by computer designers.
➢Although 123 and 321 have the same digit, their values are
different. Can you explain the reason?

April 18, 2024 unity University 8


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

April 18, 2024 unity University 9


The Decimal Number System
• Uses number 10 as its base or radix.

• Base is defined 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
April 18, 2024 unity University 10
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
- The weight of the nth digit of the number from the right of the decimal point is
equal to:
nth digit * 10-n

April 18, 2024 unity University 11


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 (20) position, the second is the
2`s(21) position, & proceeding in this way we have 4`s(22) position,
8`s(23) position, 16`s (24) position, & so on.

April 18, 2024 unity University 12


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).

April 18, 2024 unity University 13


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).

April 18, 2024 unity University 14


Conversion Among Bases
• The Possibilities

Decimal Octal

Binary Hexadecimal

April 18, 2024 unity University 15


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

April 18, 2024 unity University 16


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.

April 18, 2024 unity University 17


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 significant end.

April 18, 2024 unity University 18


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.

April 18, 2024 unity University 19


Binary to Decimal

April 18, 2024 unity University 20


Example

April 18, 2024 unity University 21


Decimal to Binary

April 18, 2024 unity University 22


Example

April 18, 2024 unity University 23


Octal to Decimal
• Technique
✓Multiply each bit by 8n, where n 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

April 18, 2024 unity University 24


Hexadecimal to Decimal
• Technique
✓Multiply each bit by 16n, where n 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

April 18, 2024 unity University 25


Octal to Binary
• Technique
✓Convert each octal digit to a 3-bit equivalent binary
representation
7058 = ?2 7 0 5
Example

111 000 101

7058 = 1110001012

April 18, 2024 unity University 26


Hexadecimal to Binary
• Technique
✓Convert each hexadecimal digit to a 4-bit equivalent binary
representation

April 18, 2024 unity University 27


Decimal to Octal
• Technique
✓Divide by 8
✓Keep track of the remainder

April 18, 2024 unity University 28


Decimal to Hexadecimal
• Technique
✓Divide by 16
✓Keep track of the remainder

April 18, 2024 unity University 29


Binary to Octal
• Technique
✓Group bits in threes, starting on right
✓Convert to octal digits

April 18, 2024 unity University 30


Binary to Hexadecimal
• Technique
✓Group bits in fours, starting on right
✓Convert to hexadecimal digits

April 18, 2024 unity University 31


Octal to Hexadecimal
• Technique
✓Use binary as an intermediary

April 18, 2024 unity University 32


Hexadecimal to Octal
• Technique
✓Use binary as an intermediary

April 18, 2024 unity University 33


Exercise – Fill the blank with Converted
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don’t use a calculator!

April 18, 2024 unity University 34


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.
April 18, 2024 unity University 35
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.
April 18, 2024 unity University 36
Binary Addition (2 of 2)
• Two n-bit values
✓Add individual bits
✓Propagate carries
✓E.g.,

1 1
10101 21
+ 11001 + 25
101110 46

April 18, 2024 unity University 37


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).

April 18, 2024 unity University 38


Additive Method of Subtraction
• When subtraction is implemented by means of digital computers, the direct
method of subtraction is found to be less efficient than the Additive Method Of
Subtraction. The method of subtraction by an additive approach is known as
complementary subtraction.

• In order to understand complementary subtraction it is necessary to know what


is meant by the complement of a number.

• Definition:

• For a number which has n digits a complement of the number is the difference
between the number and the base raised to the nth power minus one.

April 18, 2024 unity University 39


Additive Method of Subtraction
• Example:
• Find the complement of 3710
• Solution
• Since the number has 2 digits and the value of the base is 10, so (base) n-
1 = 102-1=99
• Now 99-37=62
• Thus the complement of 3710=62
• But in case of binary number, it is not necessary to go through the usual
process of obtaining complement. To obtain the complement of binary
number transform all its 0`s to 1`s and all its 1`s to 0`s.
• Example
• The complement of 1011010 is 0100101.

April 18, 2024 unity University 40


Additive Method of Subtraction
• Since we have seen how to obtain complement of a number, we will now see how
subtraction is performed using complement.

• In subtracting binary number using complement method the following steps are
useful.

• Steps:

• 1. fined complement of the number (subtrahend)

• 2. add the complement to the number from which you are taking away
(minuend)

• 3. if there is a carry of one add it to obtain the result; if there is no carry, re-
complement the sum and attach a negative sign to obtain the result.
April 18, 2024 unity University 41
Additive Method of Subtraction
• Example:

Subtract 01110002 from 10111002

Exercise

1 adds the binary numbers 1011 and 101 in both binary and decimal form.

2 Subtract 01101112 from 11011102.

3 Find the complement of the following number

a) 49510 b) 2910

c) 48 d) c16

4) Find the complement of the following binary number

a) 10 b) 101

c) 101101 d) 011011

5) Subtract 1101112 from 101110 using complementary method.

April 18, 2024 unity University 42


Binary Multiplication
• Binary, two n-bit values
• As with decimal values
• E.g.,

1110
x 1011
1110
1110
0000
1110
10011010

April 18, 2024 unity University 43


Coding Methods
Data has to be converted into a form which is understandable by computers before
processing. Computers use different mechanisms to represent data. These
mechanisms are called coding systems. There are different coding systems, which
convert one or more character sets into computer codes. Some are:

• BCD (BINARY CODED DECIMAL)

• EBCDIC (Extended Binary Coded Decimal Interchange Code)

• ASCII (American Standard Code for Information Interchange)

In all cases, binary coding schemes separate the characters, known as character
set, in to zones. Zone groups characters together. With in each zone, the individual
characters are identified by digit code.
April 18, 2024 unity University 44
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

April 18, 2024 unity University 45


BCD (BINARY CODED DECIMAL)
• BCD is one the early memory codes .it is based on the idea of converting
each digit of decimal number in to its binary equivalent.
• The BCD equivalent of each decimal digit is shown in the following table:

April 18, 2024 unity University 46


BCD (BINARY CODED DECIMAL)
• Note: Each decimal digit is represented in BCD by 4 bits.
• Example:
• Convert 4210 in to BCD

• Solution:

• (4)10=0100 in BCD

• 210=0010 in BCD

• 4210=0100 0010

• (42)10= 01000010 in BCD

April 18, 2024 unity University 47


BCD (BINARY CODED DECIMAL)
• Note

• Since 4 bits are used to represent a character, altogether only16 (24)


configuration is possible. Thus instead of using 4 bits with only 16
possible characters computer designers commonly use 6 bits to represent
characters in BCD. now it is possible to represent 64(26) characters.
• Note:
• Since we use 4 bits in BCD , altogether 16(2 4) configuration is possible

April 18, 2024 unity University 48


EBCDIC (extended binary coded
decimal interchange code)
• The major problem of BCD code is that only 64 characters can be
represented. This is not sufficient to represent all characters on the
keyboard.

• Hence BCD code is extended from 6-bit code to 8-bit code called EBCDIC.

• Because EBCDIC code is an 8-bit code, it can easily be divided in to two 4-


bit groups. Each of these 4-bit groups can be represented by 1
hexadecimal digit.

April 18, 2024 unity University 49


ASCII (AMERICAN STANDARD CODE
INFORMATION INTERCHANGE)
• ASCII code is one of memory code which is mostly used to represent data
internally in microcomputers. ASCII is of two types: ASCII-7 and ASCII-8

• ASCII-7 is a 7-bit code that allows 128(27) different characters. The first
three bits are used as zone bit and the rest 4 bits indicate the digit.

• ASCII-8 is an 8-bit code that allows 256(28) different characters. The


additional 1 bit is added to the zone bit.

April 18, 2024 unity University 50


Reading Assignment

✓UNICODE

✓Exceed three

April 18, 2024 unity University 51

You might also like