Data Representation and Numbering System@chapter (2)
Data Representation and Numbering System@chapter (2)
MARCH, 2024
Binary Arithmetic
Coding methods
Computers use binary digits (bits) to represent data, where each bit can have a value of
0 or 1. These binary digits are then grouped into larger units to represent different types
of data.
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.
BASIC COMPUTER PROGRAMMING 3
Cont…
•Binary numbers are used to represent data in computers because computers are
electronic devices that operate using two voltage levels, typically represented as 0 and 1.
•This binary system aligns well with the on/off nature of electronic switches within a
computer's circuitry. By using binary numbers, computers can efficiently store, process,
and transmit data in a way that is compatible with their electronic components. This
simplifies the design and operation of computer systems, making them more reliable and
efficient for handling complex tasks.
code.
The standard code form that most PCs use to allow for communication between
systems.
•Another version is ASCII-8, also called extended ASCII, which uses 8 bits for each
character, can represent 256 different characters.
It stands for Extended Binary Coded Decimal Interchange Code. This is similar to ASCII
and is an 8-bit code used in computers manufactured by International Business Machines
(IBM).
Similarly, if EBCDIC coded data is to be used in an ASCII computer, EBCDIC code has to
be transformed to ASCII.
•It provides a unique number for every character, no matter what the language and platform
be. Unicode originally used 16 bits which can represent up to 65,536 characters. It is
maintained by a non-profit organization called the Unicode Consortium.
•
BASIC COMPUTER PROGRAMMING 11
Data Representation: Storing Sound
Sound is a form of energy that we perceive through our ears.
In computing, sound is represented digitally as binary data.
Sound can be stored in several formats, with the most common ones being
.wav, .mp3, .ogg, etc.
Analogue and Digital Sound
Analogue sound is how humans hear it in nature, continuous and fluid.
Computers, however, represent sound by collecting many small samples and
stitching them together, this is called digital sound.
BASIC COMPUTER PROGRAMMING 12
Cont…
Digital representation is done by a process known as sampling. It involves
measuring the sound wave’s intensity at fixed intervals.
The rate at which this measurement is done is called the sampling rate.
Higher sampling rate results in better sound quality but also requires more
space to store the data.
The more pixels an image has, the higher the resolution – a high-resolution
image conveys more visual information than low-resolution images, but at a
higher data cost.
BASIC COMPUTER PROGRAMMING 15
Cont…
Image can be represented by a list of pixels.
Imagine all the rows of pixels on the screen laid out end to end in one long
row.
This gives the pixel list, and a pixel's location in the list corresponds to its
position on the screen.
A pixel's color is represented by a binary code, and consists of a certain
number of bits.
In a monochrome (black and white) image, only 1 bit is needed per pixel: 0
for black, 1 for white, for example. A 16 color image requires 4 bits per
pixel.
BASIC COMPUTER PROGRAMMING 16
Cont…
Video Representation: Videos combine image and audio data to create
moving pictures. Video formats like AVI, MP4, and MOV encapsulate both
video and audio streams, along with additional information such as
timestamps and metadata.
•Data is represented in binary form, with the bit being the basic unit of data. Each bit can
hold a value of either 0 or 1.
•Bit: A bit is the smallest unit of data in computing and digital communications.
•The term is a portmanteau of ‘binary’ and ‘digit’. Bit can have a value of either 0 or 1,
corresponding to the binary system of numbers.
BASIC COMPUTER PROGRAMMING 18
Cont…
oByte: A byte is a unit of digital information that consists of 8 bits. It is the most common
unit used to represent character data (for example, a letter, number, or punctuation mark).
Data is typically represented in larger units for ease of interpretation in our world of
increasing data sizes.
A megabyte (MB) denotes approximately one million bytes (or exactly 1,048,576
bytes).
A gigabyte (GB) denotes approximately one billion bytes, and a terabyte (TB), one
trillion bytes.
For very large data storage or data transfer rates, we use petabyte (PB), exabyte (EB), zettabyte
(ZB), and yottabyte (YB). Each of these is 1,000 or 1,024 times larger than the previous, depending
on whether decimal or binary units are being used.
For instance, the size of a small text file might be best expressed in kilobytes, while the capacity of a
hard drive may be given in terabytes. The average internet speed could be measured in megabytes per
second (Mbps), indicating the amount of data that can be transmitted each second.
BASIC COMPUTER PROGRAMMING 21
Number System
Number systems are the technique to represent numbers in the computer
system architecture, every value that you are saving or getting into/from computer memory
has a defined number system.
A number system has a unique base, which depends upon the number of symbols. The
number of symbols used in a number system is called the base or radix of a number system.
numbers and figures. It is the unique way of representing of numbers in arithmetic and
algebraic structure.
The numeral system(Number system) Represents a useful set of numbers, reflects the
The digits from 0 to 9 can be used to form all the numbers. With these digits, anyone
can create infinite numbers. For example, 156,3907, 3456, 1298, 784859 etc
Numbers used in mathematics are mostly decimal number systems. In the decimal number system, digits
used are from 0 to 9 and base 10 is used. There are many types of numbers in decimal number system,
Numbers that are represented on the right side of the zero are termed Positive Numbers. The value of these
numbers increases on moving towards the right. Positive numbers are used for Addition between numbers.
Example: 1, 2, 3, 4.
Numbers that are represented on the left side of the zero are termed Negative Numbers. The value of these
numbers decreases on moving towards the left. Negative numbers are used for Subtraction between
called Positive Numbers or Counting Numbers. Natural Numbers are represented by the symbol N.
Whole Numbers are basically the Natural Numbers, but they also include ‘zero’. Whole numbers are
Integers are the collection of Whole Numbers plus the negative values of the Natural Numbers. Integers do
not include fraction numbers i.e. they can’t be written in a/b form. The range of Integers is from the Infinity
at the Negative end and Infinity at the Positive end, including zero. Integers are represented by the symbol Z.
both are integers and b≠0. All the fractions are rational numbers but not all the rational numbers are
fractions.
Irrational numbers are the numbers that can’t be represented in the form of fractions i.e. they can not
be written as a/b.
Numbers that do not have any factors other than 1 and the number itself are termed as Prime
Numbers. All the numbers other than Prime Numbers are termed as Composite Numbers except 0.
Number system with a base value of 10 is termed a Decimal number system. It uses 10
digits i.e. 0-9 for the creation of numbers. Here, each digit in the number is at a specific
place with place value a product of different powers of 10. Here, the place value is termed
from right to left as first place value called units, second to the left as Tens, so on Hundreds,
Thousands, etc. Here, units have the place value as 100, tens have the place value as 101,
hundreds as 102, thousands as 103, and so on.
Example:
◦ Consider the number 954:
Number System with base value 2 is termed as Binary number system. It uses 2 digits i.e.
0 and 1 for the creation of numbers. The numbers formed using these two digits are
termed Binary Numbers. The binary number system is very useful in electronic devices
and computer systems because it can be easily performed using just two states ON and
Decimal Numbers 0-9 are represented in binary as: 0, 1, 10, 11, 100, 101, 110, 111, 1000,
and 1001. For example, 14 can be written as 1110, 19 can be written as 10011, 50 can be
written as 110010.
BASIC COMPUTER PROGRAMMING 30
Cont…
Octal Numbers can be converted to Decimal values by multiplying each digit with the place
value and then adding the result.
Octal Numbers are useful for the representation of UTF8 Numbers. Example,
Number System with base value 16 is termed as Hexadecimal Number System. It uses 16
digits for the creation of its numbers.
Digits from 0-9 are taken like the digits in the decimal number system but the digits from 10-
15 are represented as A-F i.e. 10 is represented as A, 11 as B, 12 as C, 13 as D, 14 as E, and
15 as F. Hexadecimal Numbers are useful for handling memory address locations.
The hexadecimal number system provides a condensed way of representing large binary
numbers stored and processed. Examples,
We can convert 10101 to the decimal number form in the following way:
= 2 + 240 + 256
=498
= 2 + 48 + 64
=114
binary number form in the following way: The decimal number 30 is expressed
as (30)10 = (11110)2.
While converting a number from the decimal number system to the hexadecimal number
system, we need to carefully observe the base of the number.
The number needs to be divided by 16 until the quotient is zero. Observe the following
table which shows the representation of decimal numbers and hexadecimal numbers.
Step 1: Divide the given decimal number system value by 16 and note
the remainder.
Step 2: Divide the quotient by 16. Repeat this until you get a quotient equal
to zero.
Step 3: Use the characters A, B, C, D, E, F in place of 10, 11, 12, 13, 14, 15
in the remainders respectively, wherever needed.
Step 4: Follow the reverse order pattern to arrange all the values of the
remainder.
Step 5: The obtained number is the required hexadecimal number.
Repeatedly multiply the integer by the new base b and save the integer part of the
result (will never exceed b) until 0 fraction or enough digits
The digits for the new base are those integers with the MS digit being that computed
first
(0.6875)10 = (?)2
radix point
2. Convert Fraction Part: 0.513 to Base 8:
Get 4 octal digits in the
Fraction for rounding to
3 significant digits
Unsigned integers are used for addressing purposes in the computer (especially for
assembly language programmers)
1. Sign-and-Magnitude
2. Ones Complement
3. Twos Complement
The leftmost bit in the binary number represents the sign of the number.
0 if positive and
1 if negative
Sign bit
7 bits for magnitude (value)
0 => +ve 1 => –ve
a) +7 = 0 0 0 0 0 1 1 1
(–7 = 100001112)
b) –10 = 1 0 0 0 1 0 1 0
(+10 = 000010102)
Solution:
Solution: Solution:
So,
(-10)10 = 1101012
Convert –5 into twos complement representation and give the answer in 8 bits.
Solution:
First, obtain +5 representation in 8 bits 000001012
Obtain ones complement for –5
111110102
Add 1 to the ones complement number:
111110102 + 12 = 111110112
–5 in twos complement is 111110112
-15900000000000000
could be represented as
Mantissa Base
0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sign Significant
sign EXP
1bit 23bit
BASIC COMPUTER PROGRAMMING 64
IEEE 754
Standard for floating point storage
Exponent Mantissa
8 bits 24 bits
.1101011011011101 x 2 101
Only the mantissa and the exponent need to be stored to represent this number
Example.
216 then 2127+16 = 2143 and my value for the exponent would
be 143 = 100011112
0 10000001 10110000000000000000000
Example:
i. 0101112 + 0111102 = 1101012
ii. 1000112 + 0111002 = 1111112
3. Subtraction ( – )
0 – 0 = 0
0 – 1 = 1 (borrow 1)
1 – 0 = 1
1 – 1 = 0
Example:
i. 0101112 - 0011102 = 0010012
Example: 8 – 5 = 8 + (–5)
–10 + 2 = (–10) + 2
6 – (–3) = 6 + 3
Example:
510 + 310 = 0001012 + 0000112
= 0010002
= 810
11110111
+ 1
111110002 = –710
the answer
000000102 = +210
the answer
Note:
For cases other than 1 & 2 above, overflow does not occur
and there will be no EAC and the need to perform addition to
the rightmost bit does not arise
Note:
In two’s complement, EAC is ignored (do not need to be
added to the leftmost bit, like that of one’s complement)
BASIC COMPUTER PROGRAMMING 91
2. | +ve Number| > |–ve Number|
Example: (–2) + 4 = (–2) + (+4)
Solution:
• Change both of the numbers above
into twos complement representation
–2 = 1111102 +4 = 0001002
• Perform addition operation on both
numbers
(–210) => 111110 (6 bit)
+ (+410) => 000100 (6 bit)
+210 1000010
Ignore the EAC