Unit1 Data Representation - 1
Unit1 Data Representation - 1
CSIT
3RD SEM
INTRODUCTION:
Digital computers store and process information in binary form as
digital logic has only two values "1" and "0" or in other words
"True or False" or also said as "ON or OFF". This system is
called radix 2. We human generally deal with radix 10 i.e.
decimal. As a matter of convenience there are many other
representations like Octal (Radix 8), Hexadecimal (Radix 16),
Binary coded decimal (BCD), Decimal etc.
A computer uses a fixed number of bits to represent a piece of
data which could be a number, a character, image, sound, video,
etc.
The memory simply stores information as a binary pattern of 1's
and 0's.
Decimal Number System
Octal Number System
Binary Number System
Hexadecimal Number System
Binary representation is a way of expressing numbers using only two
digits: 0 and 1. Each digit in a binary number is called a "bit" (short for
binary digit). The binary system is a base-2 numeral system, as opposed
to the decimal system, which is a base-10 numeral system.
Binary is commonly used in computer science because digital systems,
including computers, use a binary system to represent and process
information. For instance, a byte, which is a basic unit of digital
information storage, consists of 8 bits and can represent 256 different
values (2^8).
In binary representation, each position in the number corresponds to a power of 2.
Starting from the rightmost digit and moving to the left, each digit represents 2
raised to the power of its position.
For example:
11012=(1×23)+(1×22)+(0×21)+(1×20)
=8+4+0+1
=13
BCD, or Binary Coded Decimal, is a binary-encoded
representation of decimal values. Unlike pure binary
representation, BCD uses a fixed number of binary bits to
represent each decimal digit. In BCD, each decimal digit is
represented by a four-bit binary code.
The BCD representation is often used in computing and
digital electronics for applications where decimal numbers
are involved, such as in numeric displays and arithmetic
operations.
The primary advantage of BCD is that it is a straightforward
way to represent decimal digits without the need for complex
conversions.
Example:
BCD representation for the decimal number 520:
• Decimal 5 is represented as 0101 in BCD.
• Decimal 2 is represented as 0010 in BCD.
• Decimal 0 is represented as 0000 in BCD.
So, the BCD representation of 725 would be 0101 0010 0000.
*Each decimal digit is converted to its 4-bit binary equivalent. BCD is not
as space-efficient as pure binary representation, but it has the advantage
of being more human-readable and easier to work with in applications
where decimal manipulation is important
Alphanumeric representation involves using a combination of letters
(alphabets) and numbers to represent information. This is commonly
used in various contexts, such as in computer programming, data entry,
and communication.
Alphanumeric characters include the 26 uppercase and 26 lowercase
letters of the English alphabet (A-Z, a-z) and the decimal digits (0-9).
In computer systems, alphanumeric characters are often encoded using
character encoding schemes such as ASCII (American Standard Code
for Information Interchange) or Unicode. These encoding schemes
assign unique numerical values to each alphanumeric character,
allowing computers to represent and process text data.
Example:
In ASCII, each alphanumeric character is assigned a unique 7-
bit or 8-bit binary code. For instance:
• The ASCII code for uppercase 'A' is 65 (binary: 01000001).
• The ASCII code for the digit '1' is 49 (binary: 00110001).
1’2 and 2’s
Subtraction using 1’s and 2’s
Fixed point Number Representation
Fixed-point representation is a way of representing numbers
with a fixed number of digits after the decimal point. Unlike
floating-point representation, which allows for a variable
number of digits before and after the decimal point, fixed-point
representation allocates a specific number of bits for the
integer and fractional parts of a number.
In fixed-point representation, a binary point is assumed at a
fixed position, and the number is represented using a fixed
number of bits for the integer and fractional parts.
The sign bit is represented as 0 for positive and 1 for negative.
Example:
In a 16-bit fixed-point representation with 8 bits for the integer part and 8
bits for the fractional part:
0110.1010 in fixed-point=6.625 in decimal
Here:
• The leftmost 8 bits represent the integer part (6).
• The rightmost 8 bits represent the fractional part (0.625)
Binary numbers can also be expressed in exponential form. The
representation of binary integers in exponential form is known as floating
point representation. The floating point representation divides the
number into two parts: the left side is a signed, fixed-point integer known
as a mantissa, and the right side is the exponent.
Floating point representation can also have a sign,
with 0 denoting a positive value and 1 denoting a
negative value. The IEEE (Institute of Electrical and
Electronics Engineers) has developed a floating point
representation standard.
Floating Point number uses Sign and Magnitude
representation for both mantissa and exponent.
Since binary numbers can have only two symbols either 0 or 1 for each
position or bit, so it is not possible to add minus or plus symbols in front
of a binary number.
We represent negative binary numbers using a minus symbol in front of
them. In computer number representation, these numbers can be
distinguishable with the help of an extra bit or flag called sign bit or sign
flag in the Binary number representation system for signed numbers.
This extra bit is called sign bit or sign flag which has a value of 0 for
positive numbers and 1 for negative binary numbers.
The representation of magnitude of positive numbers is easy and does
not need any changes.
The representation of magnitude of negative numbers is changed
accordingly to represent it.
Signed Magnitude Method :
We only add an extra sign bit to recognize negative and
positive numbers. Sign bit has 1 for negative number and 0 for
positive number.
1’s Complement Method :
Please note that MSB is always Sign bit, if it 0, then there are
no changes. MSB is always 1 in case of negative numbers. We
only take 1’s complement of negative numbers to represent in
the computer.
2’s Complement Method :
MSB is always Sign bit, if it 0, then there are no changes. MSB is always 1
in case of negative numbers. We only take 2’s complement of negative
numbers to represent in the computer.
Overflow
When two numbers of n digits are added and the sum occupies n+1 digits, we say that
an overflow has occurred. A result that contains n+1 bits can't be accommodated in a
resister with a standard length of n-bits.
For this reason many computers detect the occurrence of an overflow setting
corresponding flip-flop.
An overflow may occur if two numbers added are both positive or both negative.
For example: two signed binary numbers +70 and +80 are stored in two 8-bit
resisters.
70 0 1000110
+80 0 1010000
150 1 0010110
Since the sum of numbers 150 exceeds the capacity of the resister (since 8-bit resister
can store values ranging from +127 to -128), hence the overflow.
Overflow detection
An overflow condition can be detected by observing two carries: carry into the sign bit
position and carry out of the sign bit position.
Consider example of above 8-bit register, if we take the carry out of the sign bit
position as a sign bit of the result, 9-bit answer so obtained will be correct. Since
answer can not be accommodated within 8-bits, we say that an overflow occurred.
If these two carries are equal ==> no overflow
If these two carries are not same ==> overflow condition is produced.
If two carries are applied to an exclusive-OR gate, an overflow will be detected when
output of the gate is equal to 1.
Gray Codes:
Gray code, also known as reflected binary code or unit distance code, is a
type of binary numeral system where two successive values differ in only
one bit (binary digit). This unique property makes it valuable in various
applications where minimizing errors during transitions between numbers
is crucial.
Gray code is a binary numeral system where two successive values differ
in only one bit. It is named after the mathematician and physicist Frank
Gray. In Gray code, each decimal digit is represented by a binary code
such that only one bit changes at a time as you move from one number to
the next.
The advantage of Gray code is that it minimizes errors that can occur
during the transition between consecutive values, which is particularly
useful in applications where accurate and reliable transitions are
essential, such as in rotary encoders.
Decimal Binary Gray Code
0 000 000
1 001 001
2 010 011
3 011 010
4 100 110
5 101 111
6 110 101
7 111 100
The 9's complement (obtained by subtracting each digit from 9) of a
decimal number can be directly found by inverting the bits (changing 1s
to 0s and vice versa) of its binary representation in the code.
Example of self-complementing codes:
• Excess-3 code:
• Adds 3 to each decimal digit before representing it in binary.
• Example: Decimal 604 is represented as 1001 0011 0111
Excess – 3 code:
Excess-3 code is a self-complementing binary-coded decimal (BCD) code
that represents decimal digits using 4 bits.
1.Adding 3 to each decimal digit:
1. To get the excess-3 code, you add 3 to the decimal digit you want to represent.
2. For example, decimal 2 becomes 5, decimal 5 becomes 8.
Excess-3
Decimal Digit
Code (Binary)
0 0011
1 0100
2 0101
3 0110
Extended Binary Coded Decimal Interchange Code: (EBCDIC)
It's an 8-bit character encoding scheme used mainly on IBM mainframe and IBM
midrange computer operating systems.
• EBCDIC defines how alphanumeric characters, punctuation, and other symbols are
represented by unique 8-bit binary codes which allows computers to understand and
process text data stored in EBCDIC format.
• EBCDIC is an 8-bit code, meaning each character is represented by a unique sequence
of 8 binary digits (0s and 1s).
• Unlike ASCII, where the first 128 characters are standardized, EBCDIC has several
different code pages, each defining a specific character set for different languages and
requirements.
• This flexibility in code pages allowed EBCDIC to better accommodate special
characters and accents needed for European languages, while ASCII initially focused
on English.
• Example:
• Uppercase A: 1100 0001
• Lowercase a: 1000 0001
Binary information transmitted through some form of communication medium is subject to
external noise that could change bits from 1 to 0 and vice versa.
An error detection code is a binary code that detects digital errors during transmission. The
detected errors can not be corrected but their presence is indicated.
These extra bits are chosen in such a way that the presence of errors can be detected.
Error-detecting codes are a sequence of numbers generated by specific procedures for detecting
errors in data that has been transmitted over computer networks.
When bits are transmitted over the computer network, they are subject to get corrupted due to
interference and network problems. The corrupted bits leads to spurious data being received by
the receiver and are called errors.
Error – detecting codes ensures messages to be encoded before they are sent over noisy
channels. The encoding is done in a manner so that the decoder at the receiving end can detect
whether there are errors in the incoming signal with high probability of success.
Parity Bit:
• In a parity bit scheme, a single additional bit is added to the data. The
parity bit is set to 1 or 0 to make the total number of ones (including the
parity bit) either even (even parity) or odd (odd parity).
• If an error occurs during transmission, the parity will be incorrect, and the
receiver can detect the error.
The most common error detection code used is the parity bit.
A parity bit(s) is an extra bit that is added with original message to
detect error in the message during data transmission.
Parity check is done by adding an extra bit, called parity bit to
the data to make number of 1s either even in case of even
parity, or odd in case of odd parity.
While creating a frame, the sender counts the number of 1s in it
and adds the parity bit in following way
• In case of even parity: If number of 1s is even then parity bit value is 0. If number of 1s
is odd then parity bit value is 1.
• In case of odd parity: If number of 1s is odd then parity bit value is 0. If number of 1s is
even then parity bit value is 1.
On receiving a frame, the receiver counts the number of 1s in it.
In case of even parity check, if the count of 1s is even, the frame
is accepted, otherwise it is rejected. Similar rule is adopted for
odd parity check.
Even Parity
One bit is attached to the information so that the total number of 1 bits is an even
number.
Message Parity
1011001 0
1010010 1
Odd Parity
One bit is attached to the information so that the total number of 1 bits is an odd
number.
Message Parity
1011001 1
1010010 0
Parity generator
Parity generator and checker networks are logic circuits constructed with exclusive-OR
functions. Consider a 3-bit message to be transmitted with an odd parity bit. At the
sending end, the odd parity is generated by a parity generator circuit. The output of the
parity checker would be 1 when an error occurs i.e. no. of 1’s in the four inputs is even.
P = x⊕y⊕z
Message (xyz) Parity bit (odd)
000 1
001 0
010 0
011 1
100 0
101 1
110 1
111 0
Parity Checker
Considers original message as well as parity bit
e = p⊕x⊕y⊕z
e= 1 => No. of 1’s in pxyz is even => Error in data
e= 0 => No. of 1’s in pxyz is odd => Data is error free