KEMBAR78
Module1 L3-Data Representation - Integer and Char | PDF | Character Encoding | Ebcdic
0% found this document useful (0 votes)
7 views22 pages

Module1 L3-Data Representation - Integer and Char

The document covers data representation in computing, focusing on signed and unsigned integers, binary and decimal number systems, and character encoding schemes such as ASCII, EBCDIC, and Unicode. It explains various methods for representing signed integers, including sign-magnitude, one's complement, and two's complement, along with their advantages and limitations. Additionally, it discusses the structure and usage of different character encoding systems to accommodate various languages.

Uploaded by

anish thakur
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)
7 views22 pages

Module1 L3-Data Representation - Integer and Char

The document covers data representation in computing, focusing on signed and unsigned integers, binary and decimal number systems, and character encoding schemes such as ASCII, EBCDIC, and Unicode. It explains various methods for representing signed integers, including sign-magnitude, one's complement, and two's complement, along with their advantages and limitations. Additionally, it discusses the structure and usage of different character encoding systems to accommodate various languages.

Uploaded by

anish thakur
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/ 22

Module-1

Data Representation
Dr. Jaishree Mayank
Contents
• Signed number representation,
• Real-Number Representation
• Fixed and Floating-point representations
• Character representation.
Number Systems: The Basics
• We are accustomed to the so-called decimal number system.
– Ten digits :: 0,1,2,3,4,5,6,7,8,9
– Every digit position has a weight which is a power of 10.
– Base or radix is 10.
• Examples:
234 = 2 x 102 + 3 x 101 + 4 x 100
250.67 = 2 x 102 + 5 x 101 + 0 x 100 + 6 x 10-1 + 7 x 10-2
Binary Number System
• Two digits: 0 and 1
– Every digit position has a weight that is a power of 2.
– Base or radix is 2.
• Examples: 110 = 1 x 22 + 1 x 21 + 0 x 20
101.01 = 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2
Binary to Decimal Conversion
• Each digit position of a binary number has a weight.
– Some power of 2.
• A binary number: B = bn-1 bn-2 …..b1 b0 . b-1 b-2 ….. b-m
where bi are the binary digits.
Representation of Unsigned Integers
• An n-bit binary number can have 2n distinct combinations.
• For example, for n=3, the 8 distinct combinations are:
• 000, 001, 010, 011, 100, 101, 110, 111 (0 to 23-1 = 7 in decimal).

Number of bits Range in Numbers


8 0 to 28 -1 (0-255)
16 0 to 216 -1 (0-65535)
32 0 to 232 -1 (0-4294967295)
64 0 to 264-1 (18 quintillion)
• An n-bit binary integer:
• bn-1 bn-2 …..b1 b0
• Equivalent unsigned decimal value:
• D = bn-1x 2(n-1) + bn-2x 2(n-2) …..+ b1x 2(1) b0x 2(0)
where bi are the binary digits.
• Each digit position has a weight that is some power of 2.
Representation of Signed Integers
• Many of the numerical data items that are used in a program are
signed (positive or negative).
• Ques on:: How to represent sign?
• Three possible approaches:
• a) Sign-magnitude representation
• b) One’s complement representation
• c) Two’s complement representation
Sign-magnitude Representation Signed
Integers
• For an n-bit number representation:
▪ The most significant bit (MSB) indicates sign (0: positive, 1: negative).
▪ The remaining (n-1) bits represent the magnitude of the number.
▪ Range of numbers: – (2n-1 – 1) to + (2n-1 – 1)
• n -1th bit is the sign bit.

Problem?
Sign-magnitude Representation
• Addition is performed if sign bits of both the input numbers are same and if they are
different, then subtraction is performed.

• Sign bit of the resultant is ’1’ if both the numbers are negative and the Sign bit is ’0’ if
both the numbers are positive.

• For subtraction,

• if |a| > |b|, then sign bit of a − b is ’0’,

• if |a| < |b|, then sign bit of a − b is ’1’.

• If the result of an operation goes out of the range, then overflow/underflow is


said to occur.
1’ Complement Representation
• Positive numbers are represented exactly as in sign-magnitude form.
• Negative numbers are represented in 1’s complement form.
• How to compute the 1’s complement of a number?
• Complement every bit of the number (1->0 and 0->1).
• MSB will indicate the sign of the number (0: positive, 1: negative).
1’ Complement Representation
Decimal 1’s Decimal 1’s
Complement Complement
To find the representation of, say,
+0 0000 -0 1111 -4, first note that
+1 0001 -1 1110 +4 = 0100
+2 0010 -2 1101 -4 = 1’s complement of 0100 = 1011

+3 0011 -3 1100
+4 0100 -4 1011
+5 0101 -5 1010
+6 0110 -6 1001
+7 0111 -7 1000
1’ Complement Representation
• Range of numbers that can be represented in 1’s complement:
Maximum :: + (2n-1 – 1)
Minimum :: - (2n-1 – 1)
Problem: Two different representations of zero.
+0 -> 0 000….0
-0 -> 1 111….1
Advantage of 1’s complement representation:
• Subtraction can be done using addition.
• Leads to substantial saving in circuitry.
2’ Complement Representation
• Positive numbers are represented exactly as in sign-magnitude form.
• Negative numbers are represented in 2’s complement form.
• How to compute the 2’s complement of a number?
• Complement every bit of the number (1->0 and 0->1), and then add one to
the resulting number.
• MSB will indicate the sign of the number (0: positive, 1: negative).
2’ Complement Representation
Example for n=4
Decimal 2’s Decimal 2’s
Complement Complement
To find the representation of, say,
+0 0000 -0 --- -4, first note that
+1 0001 -1 1111 +4 = 0100
+2 0010 -2 1110 -4 = 1’s complement of 0100 +1
= 1100
+3 0011 -3 1101
+4 0100 -4 1100
+5 0101 -5 1011
+6 0110 -6 1010
+7 0111 -7 1001
-8 1000
2’ Complement Representation
• Range of numbers that can be represented in 2’s complement:
Maximum :: + (2n-1 – 1)
Minimum :: - (2n-1)
Advantage of 1’s complement representation:
• Unique representation of zero.
• Subtraction can be done using addition.
• Leads to substantial saving in circuitry.

• Almost all computers today use 2’s complement representation


for storing negative numbers.
Some other features of 2’s complement
representation
• Weighted number representation, with the MSB having weight -2n-1.
• D= −bn−1​2n−1+bn−2​2n−2+...+b0​20

• Shift by k positions with zero padding multiplies the number by 2k.


• 00010011 = +19 :: Shift left by 2 :: 01001100 = +76
• 11100011 = -29 :: Shift left by 2 :: 10001100 = -116
Some other features of 2’s complement
representation
• Shift right by k positions with sign bit padding divides the number by 2k.
• 00010110 = +22 :: Shift right by 2 :: 00000101 = +5
• 11100100 = -28 :: Shift right by 2 :: 11111001 = -7
• The sign bit can be copied as many times as required in the beginning to
extend the size of the number (called sign extension).

• X = 00101111 (8-bit number, value = +47)


extend to 32 bits: 00000000 00000000 00000000 00101111

• X = 10100011 (8-bit number, value = -93)


Sign extend to 32 bits: 11111111 11111111 11111111 10100011
Representation of Character
• Coding schemes are: ASCII, EBCDIC, UNICODE.
• ASCII : American Standard Code for Information Interchange.
• Bits Used: 7 bits per character.
• Number of Characters Supported: 128 unique symbols (2⁷ = 128).
• Character Range: Includes English letters (A-Z, a-z), digits (0-9), punctuation marks, and control
characters (like newline \n, tab \t, etc.).
• Example:
• 'A' → Binary: 1000001 → Decimal: 65
• 'a' → Binary: 1100001 → Decimal: 97
• Advantages:
• Lightweight, efficient for English text.
• Universally supported on older systems.
• Limitations:
• Cannot represent characters from non-English languages like Hindi, Chinese, Arabic, etc.
Representation of Character
• EBCDIC : Extended Binary Coded Decimal Interchange Code.
• Bits Used: 8 bits per character.
• Number of Characters Supported: 256 (2⁸ = 256).
• Developed By: IBM, primarily for IBM mainframe systems.
• Structure: Not sequential like ASCII—characters are grouped by type (letters, numbers, control
characters, etc.).
• Example:
• 'A' → Binary: 11000001 (EBCDIC encoding differs from ASCII)
• Advantages:
• Designed for use with punched cards and older IBM systems.
• Slightly larger character set than ASCII.
• Limitations:
• Not widely used outside IBM systems.
• Incompatible with ASCII-based systems.
Representation of Character
UNICODE : It is used to capture most of the languages of the world.
• Bits Used: Originally 16 bits (2 bytes), now variable-length encoding (e.g., UTF-8, UTF-16, UTF-32).
• Characters Supported: Over 143,000 characters (and growing), across most of the world's writing systems.
• Goal: One universal encoding for all text on all platforms.
• Adopted By: Apple, IBM, Microsoft, Oracle, SAP, Google, and many others.
• Examples:
• 'A' → Unicode: U+0041
• 'ह' (Hindi character) → U+0939
• '中' (Chinese character) → U+4E2D
• Advantages:
• Supports global language representation.
• Enables multilingual computing and internationalization.
• Limitations:
• Larger memory requirements in some encodings (e.g., UTF-32).
• More complex to process than fixed-width encodings like ASCII.
Thanks

You might also like