0% found this document useful (0 votes)
39 views90 pages

Module 2 - Part 1 - FOC

Module 2 covers the binary representation of data, including number systems such as binary, octal, hexadecimal, and decimal, along with their conversions. It explains CPU architecture basics, integer representation, and the differences between signed and unsigned integers, including various methods for representing signed integers. The module also details binary operations and conversion techniques between different number systems.

Uploaded by

Abhilash S
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)
39 views90 pages

Module 2 - Part 1 - FOC

Module 2 covers the binary representation of data, including number systems such as binary, octal, hexadecimal, and decimal, along with their conversions. It explains CPU architecture basics, integer representation, and the differences between signed and unsigned integers, including various methods for representing signed integers. The module also details binary operations and conversion techniques between different number systems.

Uploaded by

Abhilash S
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/ 90

Mod

ule 2
Module 2

Binary representation of data and numbers, Integer


Representation, Data storage units - bits, bytes, kilobytes,
etc., ASCII and Unicode,

CPU Architecture and Instruction Set: Basic CPU


architecture - ALU, registers, control unit, Instruction format
and assembly language (basics only) Fetch-execute cycle
and instruction execution.
What is Number System

❑ A number system is a system representing numbers.

❑ It is also called the system of numeration and it defines a set of values to


represent a quantity.

❑ The most fundamental number system in computing is binary, which only uses
the digits 0 and 1.

❑ Digits from 0 to 9 are used to represent other types of number systems.


Types of Number Systems

❑ There are different types of number systems in which the four main types are:

Binary number system -uses 0 and 1


(Base - 2) like that (110101)2
Octal number system - uses the digits from 0 to 7.
(Base - 8) like that (726)8
Hexadecimal number system - uses the digits from 0 to 9 and A to F.
(Base - 16) like that (27FB)16
Decimal number system - uses the digits from 0 to 9.
(Base - 10) like that (1045)10
Binary Number System

❑ The binary number system uses only two digits: 0 and 1. The numbers in this system have a base of 2.

❑ The binary system is applied internally by almost all latest computers and computer-based devices
because of its direct implementation in electronic circuits using logic gates.

❑ Every digit is referred to as a bit. binary number, the rightmost digit is called least significant bit
(LSB) and leftmost digit is called most significant bit (MSB). The binary number are represent like
(110101)2

1 1 0 0 1 1
MSB LSB
Binary Number System

► Digital computers represents all kinds of data and information in the


binary system.
► Binary to Decimal Conversion Techniques:
► Multiply each bit by 2n, 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 (101011)2 = (43)10
Binary Number System

❑ Binary number system conversion into decimal and decimal equivalent of this
number is sum of product of each digit with its positional value.
❑ Binary to Decimal conversation

1100102 = 1×25 + 1×24 + 0×23 + 0×22 + 1×21 + 0×20


= 32+16 + 0 + 0 + 2 + 0
= 5010
Binary to Decimal Conversion


Decimal Number System

❑ Decimal number system is a base 10 number system having 10 digits from 0 to 9. This means
that any numerical quantity can be represented using these 10 digits. Decimal number system is
also a positional value system. This means that the value of digits will depend on its position.
Let us take an example to understand this.

123410 = 1×103 + 2×102 + 3×101 + 4×100

= 1000 + 200 + 30 + 4

= 123410
Decimal to Binary Conversion

► To convert Decimal to binary numbers, the following steps should be followed:-

► 1. Take any decimal number and divide it by “2". After dividing, you will get some results along
with the remainder.
► 2. If the decimal number chosen by you is even, then the result will be in a whole number and it
will give the remainder 0.
► 3. If the decimal number chosen by you is odd, then the number will not be divided fully and you
will get the remainder “1”.
► 4. Continue dividing the number till you get the quotient 0
► 5. Now place all the remainders in the series of Least Significant Bit (LSB) at the top and the
Most Significant bit (MSB) at the bottom.
Decimal to Binary Conversion

► 125 = 2 125 --- 1


2 62 --- 0
2 31 --- 1
2 15 --- 1
2 7 --- 1
2 3 --- 1
2 1 ----1
0
= 11111012
Binary-to-Decimal
Conversion Table

Invitation to Computer Science, C++ Version, Fourth Edition 12


Decimal to Binary Conversion Example

❑ Let us Convert the Decimal Number 75 into a Binary Number.

Division of Decimal Number


Quotient Remainder Binary
by 2

75/2 37 1 1 (LSB)
37/2 18 1 1
18/2 9 0 0
9/2 4 1 1
4/2 2 0 0 (75) 2 = 1001011

2/2 1 0 0
1/2 0 1 1 (MSB)
Binary Number System

► Binary to Octal Conversion Techniques:


► Group binary digits in a 3 bits, starting on right side.
► Convert to octal digits.
► Example 1 011 010 111 2 = (1327)8
► Binary to Hexa-decimal Conversion Techniques:
► Group binary digits in a 4 bits, starting on right side.
► Convert to hexa-decimal digits.
► Example 10 1011 1011 2 = (2BB)16
Decimal Number System

► Decimal number system is the base 10 number system and uses the digits
from 0 to 9. Using these digits you can express any quantity.
► It is what we most commonly use.
► Decimal to Binary Conversion Techniques:
► Divide each bit by 2, keep track of the remainder 🡪odd –rem=1,even
rem=0
► Continue dividing the number till you get the quotient 0.
► Now place all the remainders in the series of Least Significant Bit
(LSB) at the top and the Most Significant bit (MSB) at the bottom.
► Example (125)10 = (1111101) 2
Binary operations

► Binary addition
► Binary subtraction
► Binary multiplication
► Binary division
Binary addition

► Rules for binary addition:


Binary Addition Facts:
Rules:

0+0= 0
0+1= 1
1+0= 1
1+1= 10 (0 with a carry of 1)
1+1+1 = 11
Example

110101 + 11011
Solution:

110101
+ 11011
1010000
Addition of large binary numbers
Solve

1. (10101)2 + (10110)2
2. (10111)2 + (11000)2
3. 00111 + 01110 10101 (the value 21 = 16 + 4 + 1
Rules for binary subtraction
Subtraction of large binary numbers

11001 - 10111 = 00010


Integer Representation

❑ Integers are whole numbers or fixed point numbers. The radix point is fixed after
the LSB.

Example:

377410 is a fixed point number (integer)


2949.9410 is a floating point number (real number)

54533. 4573.55

Radix Point Moved from LSB


LSB Radix Point Fixed
A radix point is a symbol that separates the integer part of a number from its fractional part.
Fixed-Point Number
Convert 1259.125 from decimal to binary
To convert decimal number 1259.125, we convert its integer and fraction part individually and then add them
to get the equivalent binary number, as below:

To convert integer 1259 to binary, follow these steps:


For converting decimal fraction 0.125 to binary number,
Divide 1259 by 2 keeping notice of the quotient and the remainder.
follow these steps:
Continue dividing the quotient by 2 until you get a quotient of zero.
Multiply 0.125 by 2 keeping notice of the resulting integer
Then just write out the remainders in the reverse order to get the
and fractional part. Continue multiplying by 2 until you get
equivalent binary number.
a resulting fractional part equal to zero (we calculate upto
1259 / 2 = 629 with remainder 1 ten digits).
629 / 2 = 314 with remainder 1 Then just write out the integer parts from the results of
314 / 2 = 157 with remainder 0 each multiplication to get equivalent binary number.
157 / 2 = 78 with remainder 1
78 / 2 = 39 with remainder 0 0.125 × 2 = 0 + 0.25
0.25 × 2 = 0 + 0.5
39 / 2 = 19 with remainder 1
0.5 × 2 =1+0
19 / 2 = 9 with remainder 1
9/2 = 4 with remainder 1 Here is the answer to 0.125 decimal to binary number:
4/2 = 2 with remainder 0 0.001
2/2 = 1 with remainder 0 Therefore, decimal number 1259.125 converted to binary
1/2 = 0 with remainder 1 is equal:
Here is the answer to 1259 decimal to binary number: 10011101011.001
Integer Representation

❑ We learned about two different types of Integers;


1) Unsigned Integers
2) Signed Integers

❑ Unsigned Integers – that can represent only zero and positive numbers. The value of an
unsigned integer interpreted as the “magnitude of underlying binary pattern or the normal
way we convert binary to decimal.

Example: 8-bit binary number 0100 0010 B (B = Binary)


0100 0010B = 2x21 + 2x26 = 4+64 = 68 D (D = Decimal)
8bit = 0000 0000
16bit = 0000 0000 0000 0000
32bit = 0000 0000 0000 0000 0000 0000 0000 0000
64bit = 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

All above numbers represent zero in different bit systems. The bit length of each system is different.
Integer Representation

❑ In a computer, integers and floating point numbers are treated differently and processed
separately.
❑ Floating point numbers are processed in a separate processor called floating point
processor.
❑ Computers use fixed number of bits to represent integers. Commonly use bit lengths are
8bit, 16bit, 32bit and 64bit.
❑ There are two types of integers
❑ Unsigned integers: can represent zero and positive numbers only
❑ Signed integers: can represent zero, positive and negative numbers.
Different ways to represent Signed Integer:
❑ There are three schemas (ways) to represent signed integers.
❑ Sign Magnitude representation
❑ 1’s complement representation
❑ 2’s complement representation
n-bit Unsigned Integers

❑ An n-bit pattern can represent 2n distinct integers. This range from 0 to (2n)-1

n-bit Minimum 2n – 1 Maximum


8bit 0 28 – 1 255
16bit 0 216 – 1 65,535
32bit 0 232 – 1 4,294,967,295
64bit 0 264 – 1 18,446,744,073,709,551,615

When you are programming you need to select the correct and
appropriate bit size to store integers. If you want to store small
numbers less than 255, you can select 8 bit number, selecting 32 bit
length to store small numbers is a waste of resources.
Signed Integers

❑ Signed integers can represent zero, positive and negative numbers.


❑ The MSB (Most Significant Bit) – Normally the first bit from left, represent the sign of
the integer. Zero (0) to represent positive (+) sign and One (1) to represent negative (-)
sign.
❑ The magnitude of the integer represent differently in different schemas.
❑ There are three ways (schemas) to represent signed integers.

1) Sign Magnitude Representation


2) 1’s Complement Representation
3) 2’s Complement Representation

Example of Signed Integers:


+2344 is a positive integer -23434 is a negative integer
★ A signed binary's bit length must be equal to a power of 2, as of:
21 = 2; 22 = 4; 23 = 8; 24 = 16; 25 = 32; 26 = 64; …..
★ The first bit (the leftmost or MSB) indicates the sign:
0 = positive integer number
1 = negative integer number
n-bit Sign Magnitude Representation

❑ Most Significant Bit (MSB) is the sign bit.


○ If MSB = 0 then it is a positive sign (or positive number) and
○ if MSB = 1 then it is a negative sign (or negative number)
❑ The remaining (n-1) bits represent the magnitude / absolute value of
the integer interpreted according to its binary pattern.

Examples:
n=8 (8 bit number) and binary number is 0100 0001

Sign bit (MSB) is 0 🡪 this is a positive number


Absolute value 1000001 🡪 65
01000001B = +65D
B = Binary, D = Decimal
n-bit Sign Magnitude Representation

Examples:

n=8 (8 bit number) and binary number is 00000000

Sign bit (MSB) is 0 🡪 this is a positive number


Absolute value 0000000 🡪 0
00000000B = +0D

n=8 (8 bit number) and binary number is 1000 0000

Sign bit (MSB) is 1 🡪 this is a negative number


Absolute value 000 0000 🡪 0
10000000B = -0D
n-bit Sign Magnitude Representation

Problems (Drawbacks / Limitations) of Sign Magnitude Representation:

❑ There are two representation for


the number zero
❑ Even the number zero need to
have a sign, since it is not
necessary nor accurate and may
leads to confusions.
❑ Positive and negative numbers
need to process separately.
Sign Magnitude Representation
Range of numbers that can be represented
in Sign Magnitude Representation

Using n-bits, the range of numbers that can be represented in Sign


Magnitude Representation is from – (2n-1 – 1) to (2n -1 – 1).
n-bit 1’s Complement Representation

In this representation, the MSB is the sign bit and MSB=0 represent
positive and MSB=1 represent negative numbers. The remaining n-1 bits
represent the magnitude (value) of the integer.
❑ In positive integers, the value of the integer is the binary pattern (value) of
the n-1 bit magnitude. Same as Sign Magnitude Representation.

❑ For negative integers, the absolute value is the n-1 binary pattern value of
the inverse magnitude (complement).

Example: 1 000 0001B (sign bit = 1, negative integer)


Complement of 000 0001 is 111 1110 = 126D
1 000 0001B = -126D
n-bit 1’s Complement Representation

★ In the 1’s Complement


Representation, there are two
different representation for
zero;

★ 0000 0000B and 1111 1111B


hence +0 and -0

★ Since the processing method


of positive and negative
integers are different,
computer need to process the
positive and negative numbers
separately.
★ 1's complement of 0111 is "1000"
0111
inverting each bit
1000
★ 1's complement of 1100 is "0011"
1100
inverting each bit
0011
1’s complement representation

★ 1’s complement of a binary number is another binary


number obtained by inverting (toggling or flipping)
all bits in it.
★ i.e., transforming the 0 bit to 1 and the 1 bit to 0.In
the 1’s complement format , the positive numbers
remain unchanged . The negative numbers are
obtained by taking the 1’s complement of positive
counterparts.
★ Eg: +9 will be represented as 0000 1001 in eight-bit
notation and -9 will be represented as 1111 0110,
which is the 1’s complement of 00001001.
Find the 1’s complement : (-55)
Steps:
1) Find the binary value of the given number (here 55)
55(10) = 11 0111(2)
The least number that is:
1) Determine the signed binary number bit length:
1) a power of 2
The base 2 number's actual length, in bits: 6.
2) and is larger than the actual length, 6,
A signed binary's bit length must be equal to a power of 2, as of:
21 = 2; 22 = 4; 23 = 8; 24 = 16; 25 = 32; 26 = 64; ... 3) so that the first bit (leftmost) could be
zero
The first bit (the leftmost) or MSB indicates the sign:
=== is: 8.
0 = positive integer number, 1 = negative integer number
1) Get the positive binary computer representation on 8 bits
55(10) = 0011 0111 Take 1’s complement of 0011 0111
1) The 1's complement of -55 is 1010 0010
Range of numbers that can be
represented in 1’s complement form

Using n-bits, the range of numbers that can be represented in


1’s complement form is from – (2n-1 – 1) to (2n -1 – 1).
For example, using 4-bits, it is possible to represent integers
numbers from -7 to +7 in a 1’s complement form representation.
n-bit 2’s Complement Representation

In 2’s Complement Representation also the MSB is the sign bit 0 represent
positive and 1 represent negative integers.

★ For positive integers, the value of the integer equal to the magnitude of
n-1 binary pattern.

★ For negative integers, the absolute value of the integer equal to the
magnitude of the complement of n-1 binary pattern plus one.

Example: 1 000 0001B (MSB = 1 is a negative number)


Complement of 000 0001 = 111 1110
Let’s add 1 to the complement = 111 1111 = 127
1 000 0001B = -127D
n-bit 2’s Complement Representation

Advantages of 2’s Complement Representation

❑ There is only one representation for the


number zero (0).
❑ In binary addition and subtraction, both
positive and negative numbers can treated
together (process together)
❑ Subtraction can use the addition logic.
❑ Computers use 2’s Complement
Representation for processing integers.
2’s complement representation00

2's complement of "0111" is "1001"


2's complement of "1100" is "0100"

0111
1000 (1’s complement)
+ 0001 (Add 1)
—-------
1001 (2’s complement)
Range of Numbers : (2’s Complement Method)

Range of Numbers : (2’s Complement Method)


For n bits register, the negative lowest number that can be stored is -(2(n-1)) and
the positive largest number that can be stored is +(2(n-1)-1) .

n - bit lowest number -(2(n-1)) largest number +(2(n-1)-1) Range


4-bit -(2(4-1)) = -(23) = -8 (2(n-1)-1) = (2(4-1)-1) = (23 - 1) = +7 -8 to +7
5-bit -(2(5-1)) = -(24) = -16 (2(n-1)-1) = (2(5-1)-1) = (24 - 1) = +15 -16 to +15
6-bit -(2(6-1)) = -(25) = -32 (2(n-1)-1) = (2(6-1)-1) = (25 - 1) = +31 -32 to +31
n-bit 2’s Complement Representation
Addition, Subtraction, Overflow and Underflow

Addition of positive integers:


-5 in 2’s complement
(8-bit)
Example: n=8, 65D + 5D = 70D
0000 0101 (Binary of 5)
65D 🡪 0100 0001B
5D 🡪 0000 0101B 1111 1010 (1’s complement)
65D + 5D 🡪 0100 0110B OK 70D within the range of -128 to +127 + 1
—-----------------
★ Subtraction is the addition of positive and negative integers 1111 1011 (2’s complement)

Example: n=8, 65D – 5D = 60D 🡪 65D + (-5D) = -5

-n = 2’s complement of +n
65D 🡪 0100 0001B
-5D 🡪 1111 1011B -5 = 2’s complement of +5
65D + (-5D) 🡪 0011 1100B 🡪 60D OK within the range of -128 to +127
n-bit 2’s Complement Representation
Addition, Subtraction, Overflow and Underflow

Overflow and underflow happens when the result is not within the acceptable range

Example of Overflow: n=8, 127D + 2D = 129D (not within -128 and +127, exceed
maximum value)

127D 🡪 0111 1111B


2D 🡪 0000 0010B
127D + 2D 🡪 1000 0001B 🡪 -127D wrong answer

Example of underflow: n=8, -125D – 5D = -130D (not within -128 and +127, below
the minimum value)

-125D 🡪 1000 0011B


-5D 🡪 1111 1011B
-125D + (-5D) 🡪 0111 1110B 🡪 +126D wrong answer
n-bit 2’s Complement Representation
Range of n-bit 2’s complement signed integers

An n-bit 2’s complement integer can represent integers from -2(n-1) to +2(n-1)-1.
This can represent all the integers within the range without missing any intergers.

8bit from -128 to +127


16bit from -32,768 to +32,767
32bit from -2,147,483,648 to + 2,147,483,647
64bit from -9,223,372,036,854,775,888 to + 9,223,372,036,854,775,887
n-bit 2’s Complement Representation
decoding 2’s complement numbers

• Check the sign bit first. If sign bit = 0, the number is positive and the absolute
value if the binary value of remaining n-1 integers.
• If the sign bit = 1, the integer is negative. To get the absolute value;
• Invert remaining n-1 bits and add 1 or
• Scan from left until the first occurrence of 1. Flip all values from that point to
the left. Binary value of this pattern gives the absolute value of the negative
integer.

Example:
N=8 bit pattern = 1 100 0100 B
Negative number
Scan from right, until the first occurrence of 1, flip all values from that point to left
011 1100 B = 60 D
Represented negative value is -60 D
Binary value of 60 = 11 1100

Binary value of 60 = 0011 1100 (in 8-bit form)

60 =

0b111100
Represent -60 in 1’s complement form

60 in binary = 111100
60 in binary = 0011 1100

Change all 1 to 0 and all 0 to 1 to get the 1’s complement.


-60 is in 1’s complement is 11000011
Sign Magnitude Representation

In this representation, we can represent numbers in any number of bits (powers of 2).
There are two parts in the representation. Sign and Magnitude, as the name implies.
If we want to represent a number in n number of bits,
★ the first bit always represents the sign of the number. That is, 0 for a positive number
and 1 for a negative number.
★ the remaining bits (n-1) represent the magnitude of the number in Binary.
★ e.g. If you want to represent +25 and -25 using 8 bits: (+25) 10 = 00011001 and (-25)10 =
10011001
★ Binary value of 25 = 11001
Complement

Since Binary number system has only 2 digits (0 and 1), the
complement of one digit is the other. i.e. the complement of 0 is 1
and vice versa.

► Complement of 0 = 1
► Complement of 1 = 0
One's Complement
In this representation, there is no specific bit to represent the sign, but the MSB (Most Significant
Bit) can be used to determine the sign of the number. i.e. MSB is 0 if the number is positive and 1 if
the number is negative. Binary numbers are used and also a specific bit size is used. (e.g. 8, 16,
32, etc. bits ) or (powers of 2).
e.g. Take the previous example again
1) If the number is positive
★ (+25)10
● Convert the number to binary
○ Convert the number to binary→ (11001)2
● Set the number to specific bit size
○ Set the number to specific bit size → (0001 1001)

1) If the number is negative ★ (-25)10


● Convert the number to binary ○ Convert the number to binary -> (11001)2
● Set the number to specific bit size ○ Set the number to specific bit size -> (0001 1001)
● Get the complement of that value ○ Get the complement of that value -> (1110 0110)
Two's Complement

Two's Complement representation technique is very much similar to One's Complement


Representation. The main difference is that when the number is negative, 1 is added to
the LSB (Least Significant Bit) after getting the complement.

e.g. Let us take the same example : ( Binary value of 25 = 11001 )

● (+25)10
● Convert the number to binary → (11001)2
● Set the number to specific bit size → (0001 1001)

● (-25)10
● Convert the number to binary → (11001)2
● Set the number to specific bit size → (0001 1001)
● Get the complement of that value → (1110 0110)
● Add 1 to LSB → (1110 0110) + 1 = (1110 0111)
Two’s complement representation

One of the most widely used is called two’s complement representation. To


understand how this method works, you need to write down, in circular form,
all binary patterns from 000 . . . 0 to 111 . . . 1 in increasing order. Here is what
that circle might look like using three-digit numbers:
Two’s complement representation

In this diagram, (previous slide) the positive numbers begin at 000 and proceed in order around
the circle to the right. Negative numbers begin at 111 and proceed in order around the circle to
the left. The leftmost digit specifies whether the number is to be given a positive interpretation
(leftmost bit = 0) or a negative interpretation (leftmost bit = 1).

★ Two’s complement is widely used for representing signed numbers inside a computer.
64

Data Representation in Computer

► In modern computers, all information is represented using binary values.


► Each storage location (cell): has two states
► low-voltage signal => 0
► High-voltage signal => 1
► i.e., it can store a binary digit, i.e., bit
► Eight bits grouped together to form a byte
► Several bytes grouped together to form a word
► Word length of a computer, e.g., 32 bits computer, 64 bits computer
65

Different types of data

► Numbers
► Whole number, fractional number, …
► Text
► ASCII code, unicode
► Audio
► Image and graphics
► video

How can they all be represented as binary strings?


Common Data Representations
67

Representing Numbers

► Positive whole numbers


► We already know one way to represent them: i.e., just use base 2 number
system
► All integers, i.e., including negative integers
► Set aside a bit for storing the sign
► 1 for +, 0 for –

► Decimal numbers, e.g., 3.1415936, 100.34


► Floating point representation:
► sign * mantissa * 2 exp

► 64 bits: one for sign, some for mantissa, some for exp.
Floating point representation:

Binary numbers:
sign * mantissa * 2 exp
Convert 8.25 from decimal to binary
To convert decimal number 8.25, we convert its integer and
fraction part individually and then add them to get the For converting decimal fraction 0.25 to binary number,
equivalent binary number, as below: follow these steps:

To convert integer 8 to binary, follow these steps: Step 1: Multiply 0.25 by 2 keeping notice of the resulting
integer and fractional part. Continue multiplying by 2 until
Step 1: Divide 8 by 2 keeping notice of the quotient and the
you get a resulting fractional part equal to zero (we
remainder. Continue dividing the quotient by 2 until you get
calcuclate upto ten digits).
a quotient of zero.
Step 2: Then just write out the integer parts from the
Step 2: Then just write out the remainders in the reverse
results of each multiplication to get equivalent binary
order to get the equivalent binary number.
number.
8 / 2 = 4 with remainder 0
0.25 × 2 = 0 + 0.5
4 / 2 = 2 with remainder 0
0.5 × 2 = 1 + 0
2 / 2 = 1 with remainder 0
1 / 2 = 0 with remainder 1 Here is the answer to 0.25 decimal to binary number:
0.01
Here is the answer to 8 decimal to binary number:
1000
Therefore, decimal number 8.25 converted to binary is equal: 1000.01
Data storage units - bits, bytes, kilobytes

In data storage units, a "bit" is the smallest unit, a "byte" is made up of 8 bits, and a "kilobyte" is
made up of 1024 bytes; essentially, a kilobyte is a collection of 1024 bytes, which are each made
up of 8 bits.

● Bit: A single binary digit, either 0 or 1, representing the most basic unit of data storage.
● Byte: A group of 8 bits, allowing for more complex data representation.
● Kilobyte (KB): A unit containing 1024 bytes, often used to measure smaller file sizes.
Data storage units - bits, bytes, kilobytes

Memory is like an electronic scratch pad inside the computer. It is a storage unit to hold the data.
In the computer the data will be stored and retrieved in the form of bits and bytes. The byte will
store a single character such as a letter of the alphabet or a numeral.

● In a computer, one bit is equal to the smallest unit of data storage, which can be either a 0 or
a 1.

1) 8 BITS = 1 BYTE
2) 1024 BYTES = 1 KB
3) 1024 KB = 1 MB
4) 1024 MB = 1 GB
5) 1024 GB = 1 TB.
Representing Text 77
► Take English text for example
► Text is a series of characters
► letters, punctuation marks, digits 0, 1, …9, spaces, return (change a line), space, tab, …

► How many bits do we need to represent a character?


► 1 bit can be used to represent 2 different things
► 2 bit … 2*2 = 2 2 = 4 different things
► n bit 2n different things
► In order to represent 100 different character
► Solve 2n = 100 for n
► n= , here the refers to the ceiling of x, i.e., the smallest
integer that is larger than x:

► To represent 100 different characters, we need at least 7 bits.


► 27 = 128 (128 > 100, and hence different 100 characters can be represented )
► If n = 6 then 26 = 64 (64 < 100, so only 64 different characters possible)
Textual Information (ASCII and Unicode)
(alphabets, symbols, digits, words….)

Textual Information - To represent textual material in binary, the system assigns to each
printable letter or symbol in our alphabet a unique number (this assignment is called a
code mapping), and then it stores that symbol internally using the binary equivalent of
that number.
★ Initially, the most widely used code set for representing characters internally in a
computer system was ASCII, an acronym for the American Standard Code for
Information Interchange. ASCII is an international standard for representing textual
information that uses 8 bits per character, so it is able to encode a total of 2 8 = 256
different symbols.
★ These are assigned the integer values 0 to 255. However, only the numbers 32 to 126
have been assigned to printable characters. The remainder either are unassigned or
are used for representing non printing control characters such as tab, form feed, and
return. Figure 4.3 shows the ASCII conversion table for the numerical values 32–126.
Textual Information (ASCII and Unicode)

The code set called Unicode, developed in the early 1990s, has gained in
popularity because it uses, at a minimum, a 16-bit representation for
characters rather than the 8-bit format of ASCII. This means that it is able to
represent at least 216 5 65,536 unique characters instead of the 2 8 = 256 of
ASCII.
(Note: Unicode is a superset of ASCII. The decimal values 0–127 represent
exactly the same characters in both ASCII and Unicode.)
It might seem as though 256 characters should be more than enough to
represent all the textual symbols that we would ever need
—for example, 26 uppercase letters, 26 lowercase letters, 10 digits, and a few
dozen special symbols, such as + = − { } ] [\: ” ? > < . , ; % $ # @.
UNICODE

● Add that all together and it still totals only about 100 symbols, far less than the 256
that can be represented in ASCII.
● However, that is true only if we limit our text to Arabic numerals and the Roman
alphabet.
● The world is growing more connected all the time—helped along by computers,
networks, and the web—and it is critically important that computers are able to
represent and exchange textual information using the widest possible range of
alphabets.
● When we start assigning codes to symbols drawn from alphabets such as Russian,
Arabic, Chinese, Hebrew, Greek, Thai, Bengali, Sanskrit, Cherokee, Inuit, and Braille,
as well as mathematical symbols, linguistic marks such as the tilde, umlaut, and
accent grave, and numerous graphical symbols, it quickly becomes clear that ASCII
does not have enough room to represent them all.
Unicode

● Unicode, with its 16 bits and space for over 65,000 symbols, was
initially considered large enough to accommodate this enormous
range of text.
● However, it turned out that even 16 bits proved insufficient to
handle the exploding range of textual information being produced
around the world, and
● Unicode now includes a 32-bit variant in which each separate
character is represented using 32 binary digits, allowing for the
possibility of 232 distinct textual symbols, or about 4 billion!
● Currently Unicode has assigned formal mappings to more than
128,000 characters drawn from over 135 modern and historical
alphabets, including such rarities as Egyptian hieroglyphics.
83

There needs a standard way


► ASCII code: American Standard Code for Information Interchange
► ASCII codes represent text in computers, communications equipment, and
other devices that use text.
► 128 characters:
► 33 are non-printing control characters (now mostly obsolete)[7] that affect
how text and space is processed
► 94 are printable characters
► space is considered an invisible graphic
► The standard ASCII character set is only 7 bits, and characters are represented
as 8-bit bytes with the most significant bit set to 0.
► The extended ASCII character set includes 127 more 8-bit characters, where
the most significant bit is set to 1. The extended ASCII character set includes
the binary values from 128 (1000 0000) through 255 (1111 1111).
84

ASCII code

● Capital letters :
A to Z : 65 to 90

● Small letters :
a to z : 97 to 122

● * 42 (multiplication)
● + 43 (plus / addition)
● - 45 (minus / subtract)
● / 47 (divide)
● < 60
● = 61
● > 62
86

There needs a standard way

► Unicode
► international/multilingual text character encoding system,
tentatively called Unicode
► Currently: 21 bits code space
► How many diff. characters?
► Encoding forms:
► UTF-8: each Unicode character represented as one to four 8-but
bytes
► UTF-16: one or two 16-bit code units
► UTF-32: a single 32-bit code unit
Binary Representation of Numeric and Textual
Information

► Characters are mapped onto binary numbers


► ASCII code set

► 8 bits per character; 256 character codes


► UNICODE code set

► 16 bits per character; 65,536 character codes


► Text strings are sequences of characters in some
encoding
Invitation to
Computer
87 Science,
C++ Version,
Three alphanumeric codes

★ Three alphanumeric codes are in common use. The three codes are
known as Unicode, ASCII (which stands for American Standard Code
for Information Interchange), and EBCDIC (Extended Binary Coded
Decimal Interchange Code).

★ EBCDIC was developed by IBM. Its use is restricted mostly to IBM and
IBM-compatible mainframe computers and terminals. The Web makes
EBCDIC particularly unsuitable for current work. Nearly everyone
today uses Unicode or ASCII. Still, it will be many years before EBCDIC
totally disappears from the landscape.
Y o u
a nk
Th

You might also like