Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views41 pages

Data Representation

The document provides an overview of binary representation and number systems used in computer organization, including decimal, binary, hexadecimal, and their conversions. It explains concepts such as two's complement for negative numbers, data representation for integers, characters, strings, and colors in computer systems. Additionally, it discusses the limitations of 8-bit registers and the ASCII encoding scheme for character representation.

Uploaded by

Ketaki Bhate
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)
16 views41 pages

Data Representation

The document provides an overview of binary representation and number systems used in computer organization, including decimal, binary, hexadecimal, and their conversions. It explains concepts such as two's complement for negative numbers, data representation for integers, characters, strings, and colors in computer systems. Additionally, it discusses the limitations of 8-bit registers and the ASCII encoding scheme for character representation.

Uploaded by

Ketaki Bhate
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/ 41

Kanha Korgaonkar

BINARY
REPRESENTATION
COMPUTER ORGANIZATION
BIT(b)
BASIC UNIT OF INFORMATION IN COMPUTER SYSTEMS
BYTE(B)
A COLLECTION OF 8 BITS WHICH CAN STORE A
SINGLE CHARACTER.
1B = 8b
Decimal Number
System
- POSITIONAL SYSTEM (EACH POSITION REPRESENTS A POWER
OF BASE-10)
- USES 10 DIGITS (0,1,2,3,4,5,7,8,9) TO REPRESENT ANY NUMBER
OF ANY SIZE.
- MOST WIDELY USED NUMBER SYSTEM.
- DECIMAL CAN BE USED AS A SEPARATOR TO REPRESENT A
FRACTIONAL PART.
- +/- SIGN CAN BE USED TO INDICATE WHETHER THE NUMBER IS
GREATER THAN OR LESS THAN 0.
6275 base 10
6275₁₀
6275
6000+200+70+5 = 6275
Binary Number
System
- POSITIONAL SYSTEM (EACH POSITION REPRESENTS A POWER
OF BASE-2)
- USES 2 DIGITS (0,1) TO REPRESENT A NUMBER.
- MOST WIDELY USED NUMBER SYSTEM IN COMPUTER SCIENCE.
69 base 2
69₂
64+4+1 = 69
LET'S DO SOMETHING FUN!
Here's another way to do it:
Repeatedly divide the decimal number by two and retain the remainders. Read them
from last to first.

69/2 = 34 q , r 1
34/2 = 17 q, r 0
17/2 = 8 q, r 1
8/2 = 4 q, r 0
4/2 = 2 q, r 0
2/2 = 1 q, r 0
1/2 = 0 q, r 1
END WHEN NUMERATOR IS 0

01000101
To convert a number from binary to decimal integer
101110
0*1 + 1*2 + 1*4 + 1*8 + 0*16 + 1*32
= 0 + 2 + 4 + 8 + 32 base 10
= 46 base 10
What about negative numbers?
Two's complement
Two's complement is a mathematical operation to reversibly convert a positive
binary number into a negative binary number with equivalent value, using the
binary digit with the greatest place value to indicate whether the binary number
is positive or negative.

Advantage of Two's Complement: Helps to carry out operations (addition,


subtraction, multiplication) easily.
Most Significant Bit
bit that is farthest to the left (i.e. having the most value)
Least Significant Bit
bit that is farthest to the right (gives us the units value and helps us understand
if the number is even or odd.)
Converting a negative number to binary
Write the absolute value of the number in binary.
Invert the digits (change all the ones to zeroes and zeroes to ones).
Add one. (1 + 1 becomes 0 and 1 gets carried forward)
Some important stuff
Using two's complement, the largest positive number that can be stored in an
8-bit register is 01111111 -> +127
largest negative number is 11111111 -> -1
smallest positive number is 00000001 -> 1
smallest negative number is 10000000 -> -128
A problem arises:
-2 in binary (represented by Two's Complement) is 1110. But 14 in binary
(unsigned number) is also 1110. How does the computer know which one is
which?
It doesn't. Programmer (or the author of the interpreter or compiler in case of
higher level languages) must tell the program how to behave in case of
different operations. Luckily, the basic arithmetic (addition and subtraction)
remains the same in two's complement and unsigned numbers.

-2 + 1 = -1 1110 + 0001 = 1111


14 + 1 = 15 1110 + 0001 = 1111
Representing Fractions in Binary in fixed point representation
(unsigned numbers i.e. positive and negative are non distinguishable):
Binary Point is used to separate the fractional part from the whole part.
The number 4.5 has 4 in integer part and 1/2 in fraction part. To convert this to
binary, since we have 8 bits, we can use 4 bits for the integer part and 4 bits for
the fraction part.

4 is 0100 in binary. 0.5 or half is 2⁻¹


Representing Fractions in Binary in Two's Complement
(signed numbers i.e. where we need to have positive and negative signs):

First use fixed point method to convert absolute value to decimal, then invert
the digits and add 1.
Hexadecimal
Number System
- POSITIONAL SYSTEM (EACH POSITION REPRESENTS A POWER
OF 16)
- USES 16 DIGITS (0,1,2,3,4,5,7,8,9,A,B,C,D,E AND F) TO
REPRESENT A NUMBER.
1EB5 BASE 16 --> BASE 10
= 1*4096+E*256+B*16+5*1
= 1*4096+14*256+11*16+5*1
= 4096+3584+176+5 = 7861
How to convert base-10 to base-16 numbers?
Repeatedly divide the decimal number by 16 until the last
numerator becomes 0, and retain the remainders. Reading the
remainders from last to first gives us the HEX number.

7861/16: q 491, r 5
491/16: q 30, r 11 (B)
30/16: q 1, r 14 (E)
1/16: q 0, r 1

:. 7861 base 10 = 1EB5 base 16


What do HEX numbers do?

A long string of 0s and 1s is hard to read. Here’s 2021 in binary:


11111100101. In a slightly longer string of 0s and 1s, you lose your
place pretty easily, and it’s hard to find where you were. It’s like
being lost in a woods where all the trees look the same.
So we say “What if we took those 0s and 1s and grouped them
together? We could express four of those bits as one digit.” So
2021 becomes 7E5. Much more compact, much easier to read, and
harder to get lost.
QUESTION
Can an 8-bit register (which stores integers in two's complement)
store 8F base 16 + 2B base 16?
QUESTION
Can an 8-bit register (which stores integers in two's complement)
store 8F base 16 + 2B base 16?

8*16 + 15*1 = 143


2*16 + 11*1 = 43
143 + 43 = 186

:. 8F base16 + 2B base 16 =
186 base 10

But, the maximum positive


value of a two's complement
that can be stored in an 8-bit
register is 127 base 10.

So we cannot store this


number in an 8 bit register.
Data
Representation
Integers
If we use 8b to represent an integer number, there can be 2⁸ =
256 representations (0-255 if we're storing unsigned positive
integers.)

For negative numbers, we learnt the two's complement method


previously, but we can also represent positive and negative
integers by the sign and magnitude number representation. This
method represents a number's sign by allocating the MSB to
represent the sign (0 for a positive number and 1 for a negative
number). But if we're using 8 bits for representing a number,
we're utilizing one bit for the sign and thus, the number of
numbers we can store is 2⁷ (-127 to +127).
Characters
The American Standard Code for Information Interchange (ASCII)
is a character encoding scheme originally based on the English
alphabet, and is used to represent text in computer systems. To
do that, a number is assigned to each character from 0 to 127.
A=65,B=66....K=75.. and so on.

ASCII uses 7 bits to store each character, that's why it can


represent 2⁷ = 128 different representations (0-127).

It contains the latin alphabet (lowercase a-z and uppercase A-Z),


as well as digits (0-9) and symbols (@, ?, >, ;, etc), and some
control characters (example: carriage-return which indicates that
a document should start from a new line).

Like ASCII, there are other encoding schemes which allow for non
english characters, graphic symbols and math symbols to be
represented). The most widely known system is Unicode.
Strings
In a computer system, a string is a sequence of characters. If the
UTF-8 (Unicode Transformation Format 8bit) encoding scheme is
used, each character will consist of 8 bits. So, the number of bits
in a word = number of letters x 8 bits.
Colors
Monitors use pixels to display information as output. Monitors
have a specific display resolution (for example, a 4K monitor has
3840 x 2160 resolution, which means, a width of 3840 pixels and
a height of 2160 pixels i.e. 8.3 million pixels).

A pixel is the smallest controllable element in a display or a


picture represented on a screen. Every pixel in a computer color
monitor may have only one color at any moment. Each color is
made up of a combination of shades of red, green and blue. Each
pixel stores information about its state and color in a memory
location. There are many ways to represent a single color. Let's
try them out.
Learn how colors are represented

You might also like