0% found this document useful (0 votes)
81 views42 pages

Data Types and Data Encoding

The document discusses data types and encoding, focusing on how digital data is represented as sequences of bits, particularly for numbers, text, and colors. It explains various numeral systems, including binary and decimal, and how integers and real numbers are encoded in computing systems. Additionally, it covers character encoding schemes like ASCII and the RGB color model for representing colors in image processing.

Uploaded by

umarani7815
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)
81 views42 pages

Data Types and Data Encoding

The document discusses data types and encoding, focusing on how digital data is represented as sequences of bits, particularly for numbers, text, and colors. It explains various numeral systems, including binary and decimal, and how integers and real numbers are encoded in computing systems. Additionally, it covers character encoding schemes like ASCII and the RGB color model for representing colors in image processing.

Uploaded by

umarani7815
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/ 42

DATA TYPES AND DATA

ENCODING
• We have already asserted that all digital data
is encoded as a sequence of bits and that
information is associated with the various
patterns that these bits may exhibit.
• This section gives further insight into how
specific types of information are encoded and
describes some of the inner workings of a
computing system.
• We begin by discussing how numbers are
encoded and then give a brief overview of
how colors, pictures, and sound can be
encoded.
Numbers
• Numeral system
• A numeral system is a way of representing
numbers in written form.
• If these markings are interpreted using the
numeral system known as tally marking, they
correspond to the numbers one, two, and
three.
• Under tally marking, a number is represented
by making one tally mark for each unit in the
number.
• You may have used tally marking when
keeping score in a game of tic-tac-toe .
• If these markings are interpreted using the Roman numeral
system, they also correspond to the numbers one, two, and
three.
• While the Roman numeral system has well-defined rules for
representing integer numbers, the system is not widely
used today because it is difficult to understand all of the
rules and to decode larger numbers.
• If these markings are interpreted using the decimal numeral
system, they correspond to the numbers one, eleven, and
one hundred and eleven. (100 ,101 100 ,102 101 100
• ------🡪1, 10+1=11,100+10+1=111

• The decimal numeral system is a base 10 positional


numbering system
• While If the markings of are interpreted using the
binary numeral system, they correspond to the
numbers one, three, and seven. (20 ,21 20 ,22 21 20
• 1,2+1=3,4+2+1=7)
• The binary system is very similar to decimal in
that it is a positional numbering system such that
any integer number is given by a sequence of
digits where the position of each digit denotes a
power of 2 and the value represents a multiplier.
• The only real difference between decimal and
binary is that decimal is a base ten numbering
scheme, binary is a base two numbering scheme
• 1.Write the number 4 using the following
systems.
• Roman number system
• binary system
• Decimal System
• 2. Write the equivalent decimal (base 10)
number for each of the following binary
numbers.
• a. 10011
• b. 11000
Positional Numeral System
• A positional numeral system must first specify
a base, also known as the radix, that describes
how many digits exist in that particular
system.
• In the decimal numeral system, for example,
the base is 10 since it uses the 10 digits 0
through 9.
• The smallest digit of a positional numeral
system is always zero while the largest digit is
always one less than the base.
• while the decimal system is the most
commonly used system for human beings, the
binary numeral system is the most commonly
used in computing.
• The binary numeral system, as the name
implies, uses only two digits.
• Any positive integer greater than one can be
used as a base in a positional numeral system.
Since there are an infinite number of bases
there are an infinite number of positional
systems.
• Notice that for numeral systems having a base
greater than 10, the symbols used for digits
will include glyphs other than those of the
decimal system.
• As an example consider the hexadecimal
system, which uses the symbol A to denote
the value 10, the symbol B to denote the value
11, and onward through F to denote the value
15.
• Interpretation of 101 10
• People almost always use the decimal numbering
system when writing numbers and therefore usually
assume that the base is 10.
• In situations where the radix may not be clear, however,
it is useful to express the base by using a subscript
notation.
• For example, the subscript in 101 10 indicates
• that the number is expressed in the decimal system,
• whereas 101 16 is a number that is expressed using a
base of 16 and
• 101 2 is a number that is expressed in binary.
• we will use subscript notation to make the radix clear.
• Whenever we write a number without a subscript we
assume that it is expressed in the decimal numeral
system
Integers as Binary Bit Strings
• Computing systems represent integer
numbers as binary bit strings.
• The binary system is a fitting choice for
computers because there are only two values
in the binary system and hence a single bit has
sufficient data capacity to store a single binary
digit
• An 8 bit string can only represents 256
numbers since an 8 bit string can only exhibit
28 unique patterns.
• This implies that the largest number that can
be encoded as an 8 bit binary number is 28– 1
or 255.
• This statement can be generalized by stating
that any binary bit string of length N can only
encode the numbers 0 through 2N – 1.
How many unique patterns does a
sequence of 5 bits generate?
Therefore, a sequence of 5 bits generates 32 unique patterns.
Real Numbers as Binary Bit Strings
• Although we can represent an integer as a sequence of
bits, is it possible to represent a real number such as
2.31 or 2.125 or even 3.1415926?
• Consider extending the meaning of a positional
numbering system to the right of the decimal such that
the positions start at –1 and decrease with distance
from the decimal.
• For example, in base 10, the value 1.625 means (1 ×
100 ) + (6 × 10–1) + (2 × 10–2) + (5 × 10–3).
• We can then represent real numbers as binary bit
strings assuming that we can determine the decimal
location.
• Consider, for example, the meaning of 1.1012
Precision as a Source of Error
• One difficulty that arises when encoding real
numbers is that there may be an arbitrary
number of digits on the right side of the
decimal value to represent even small
numbers.
• If we write 1/3 as a real number, for example,
we begin to write
0.33333333333333333333333333 but soon
realize that we will never be able to write as
many digits as are required for a completely
accurate representation.
• Most real numbers cannot be exactly encoded by
• the encoding scheme described earlier and are
therefore represented as an approximate value.
Computer applications typically, therefore, allow
• rounding errors to occur and hence computers
often produce incorrect, although highly
accurate, results.
• Precision is a measure of the accuracy of a stored
quantity.
• The precision is usually measured as the number
of available bits.
• If a computer uses 16 bits to store real numbers,
we say that the computer is precise up to 16 bits,
or that the computer uses 16 bit precision
Underflow and Overflow as Sources of
Error
• Other kinds of error can be introduced into a
computing system through underflow and overflow.
• Recall that an 8 bit binary string can only hold values
between 0 and 255. An example of overflow occurs
when a computer is instructed to add 1 to the value
255 and store the result as an 8 bit binary string.
• Of course the result should be 256 but since 256
cannot be encoded as an 8 bit binary string the result
will either be an error of some sort or, on many
computing systems, the result will actually wrap
around to 0!
• In general, overflow occurs when a computer
instruction produces a value that is too large to
be encoded by the number of bits available.
• Underflow occurs when a computer instruction
produces a value that is too small in magnitude
(i.e., very close to zero) to be encoded by the
number of bits available.
Text
• All data that is stored in a computing system is
encoded as bit strings.
• You might wonder, then, how can a bunch of
bits be made to look like text?
• Even the words that you are now reading are
stored in binary form and this information is
then presented to you as text.
• The text you are reading even has different
fonts using different sizes and weights.
• Textual characters are usually encoded as
integer values using the encoding schemes.
• Each number is arbitrarily associated with the
image that should be used when the character
is drawn on a page or shown on the computer
screen.
• The associations between numbers and text
are known collectively as a character encoding
scheme.
• In the ASCII table, the number 65 is associated
with uppercase A, whereas the number 97 is
associated with lowercase a.
• The number 38 is associated with the
ampersand (&) and the number 126 is
associated with the tilde (~).
• Since English has relatively few characters, the
ASCII table only has about 128 entries.
• Other languages, such as Japanese or Chinese,
use thousands of characters and hence the
association tables are much larger.
• Some text contained in the ASCII table is not
really pictorial but rather a command that a text
editor or text processor must follow.
• These characters are known as nonprintable text
characters because they cannot be drawn.
• The backspace key, for example, is not printable
since you do not see anything when you strike
that key, but you would expect that a text
processor would take some action whenever the
user enters a backspace.
• Nonprintable characters are shown in Figure 2.17
as an empty cell
• My first name is Arun and second name is kumar.
Write down the 16 bits that a computer would
most likely use to store these two initials in a
computer. (Hint: The encoding is given by the
ASCII table.)
• Let's convert the initials "A" and "K" from your
first and last name to ASCII values and represent
them in 16 bits:
• The ASCII value for 'A' is 65, which is represented
in binary as 01000001.
• The ASCII value for 'K' is 75, which is represented
in binary as 01001011.
• So, the 16 bits that a computer would most likely
use to store the initials "A" and "K" in a computer
are 0100000101001011.
• What text is encoded in the following? (Hint:
The encoding is given by the ASCII table.)
• a.
0011001000101011001100110011110100110
101
• To decode the binary sequence provided, we
can break it into groups of 8 bits (since each
ASCII character is represented by 8 bits). Let's
decode each group:
• 00110010 -> 50 (decimal) -> '2' (ASCII)
• 00101011 -> 43 (decimal) -> '+' (ASCII)
• 00110011 -> 51 (decimal) -> '3' (ASCII)
• 00111101 -> 61 (decimal) -> '=' (ASCII)
• 00110101 -> 53 (decimal) -> '5' (ASCII)
• So, the decoded text is: 2+3=5.
• What text is encoded in the following? (Hint:
The encoding is given by the ASCII table.)
• A.01000010011010010111010001110011
• B. 001111000011001100110011
Colors
• The human eye perceives color through three
types of biological photosensors known as cones.
• Each cone is attuned to one of three wavelengths
that correspond roughly to red, green, and blue
light.
• The individual responses of all cones combine to
form the perception of a single color at a single
• point within the field of view.
• The design of this biological system suggests that
color is a three-dimensional entity.
• The RGB color model is the most common way
of representing color in image-processing
systems.
• The RGB model uses red (R), green (G), and
• blue (B) as the primary colors such that any
color can be created by combining different
amounts of these three primaries.
• By way of example, consider a flashlight that
has a slider allowing you to choose the
strength of light emitted.
• In setting the slider to 0, the flashlight is turned
completely off and generates no light, whereas in
setting the slider to 255 (the maximum setting) the
flashlight generates as much light as it is capable of
generating.
• Now consider three such flashlights: the first emits
purely red light, the second emits purely green light,
and the third emits purely blue light.
• If all three flashlights are aimed at the same spot on a
white wall any color can be projected onto the wall by
adjusting the slider values on the three lights in
different ways.
• If all sliders are set to 0, black is projected onto the
wall. If all sliders are set to 255, white is projected onto
the wall, and if all sliders are set to 128 then gray is
projected
• In computing systems, a color is usually
encoded as three integer numbers where each
number is in the interval 0 to 255.
• In addition, since each value can be one of
only 256 different values, a bit string of length
eight is sufficient for encoding each value.
• This implies that a single color will be encoded
as a bit string of length 24 since there are
three values and each value is encoded with 8
bits.

You might also like