Data Presentation 1
Data Presentation 1
Part 1
Representing Data Digitally
Data
Data values can be stored in variables, lists of items, or standalone constants.
Thus, digital data is simply some sequence of 0's and 1s representing some
information.
Bits and Bytes
4
Base 10 (Decimal numbers)
Computers store all information in the form of binary numbers. To understand
binary numbers, let's first look at a more familiar system: decimal numbers.
Base 2
1011 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20
1011 = 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 =11 in Base 10
Bits and Bytes
There are 10 types of people in the world; those who understand binary and those who don’t.
There are 10 types of people in the world; those who understand binary and those who have friends.
Hexadecimal
Binary code is too long in representation. Hexadecimal is much shorter. Hexadecimal
uses 16 digits.
Converting a binary number to a Hex number is relatively easy. Every 4 bits can convert to
a Hex.
Hexadecimal
Binary to Hex
Overflow Error
Some languages like Python, integers do not have limits on number size but,
instead, expand to the limit of the available memory.
18
Overflow Error
What Does Overflow Error Mean?
Example 1:
With 4 bits, the largest integer that can be stored is 2^4 - 1 = 15.
Example 2:
A 4-bit integer can any value in {0,1,2,..,15}. Thus, storing the value of 10 + 6
= 16 would cause an overflow error since the 16 = 10000 requires at least
5 bits.
Example 3:
If x is a 3-bit integer, then x = 111 + 111 will cause an overflow error since
the sum is 1110 which requires at least 4 bits.
20
Round Off Errors
21
Abstraction
Abstraction is the process of reducing complexity by focusing on the main idea.
By hiding details irrelevant to the question at hand and bringing together related
and useful details, abstraction reduces complexity and allows one to focus on the
idea.
import random
print(random.randrange(10)) # random number from 0 - 9
We don't need to know how the randrange() function is implemented to be able use it.
Abstraction
Bits are grouped to represent abstractions. These abstractions include, but are
not limited to, numbers, characters, and color.
Sequences of 0's and 1's represent a string of characters, a numeric grade and a color
in the examples below. The color example is done using Processing.
23
Encoding
A computer cannot store “letters” or “pictures”. It can only work with bits(0 or 1).
To represent anything other than bits, we need rules that will allow us to convert a
sequence of bits into letters or pictures. This set of rules is called an encoding scheme, or
encoding for short. For example,
ASCII
ASCII(American Standard Code for Information Exchange) is an encoding scheme
that specifies the mapping between bits and characters. There are 128 characters in the
scheme. There are 95 readable characters and 33 values for nonprintable characters like
space, tab, and backspace and so on.
The readable characters include a-z, A-Z, 0-9 and punctuation. In ASCII, 65 represents A, 66
represents B and so on. The numbers are called code points. But ASCII only uses 8 bits. It
does not have enough bits to encode other characters and languages(Chinese, French,
Japanese).
Similar to ASCII, Unicode provides a table of code points for characters: "65 stands for A, 66
stands for B and 9,731 stands for ☃”. UTF-32(Unicode Transformation Format),
UTF-16 and UTF-8 are three encodings that use the Unicode table of code points.
Of the three, UTF-8 is by far the most widely used encoding. It is the standard encoding for all
email and webpages(HTML5).
ASCII Sample
encode
To encode something in ASCII,
follow the table from right to left,
substituting letters for bits.
decode
Unicode
So, how many bits does Unicode use to encode all these characters? None.
Because Unicode is not an encoding.
Unicode first and foremost defines a table of code points for characters. That's a
fancy way of saying "65 stands for A, 66 stands for B and 9,731 stands for ☃”.
To represent 1,114,112 different values, two bytes aren't enough. Three bytes are,
but three bytes are often awkward to work with, so four bytes would be the
comfortable minimum.
UTF-32 very simple, but often wastes a lot of space. For example, if A is always
encoded as 00000000 00000000 00000000 01000001 and B as 00000000 00000000
00000000 01000010 and so on, documents would bloat to 4x its necessary size.
Digital vs. Analog
Computers can only understand digital data: discrete values like a list of integers,
sequences of 0's and 1's.
Analog data have values that change smoothly, rather than in discrete intervals,
over time. Some examples of analog data include temperatures over a period of
time, pitch and volume of music, colors of a painting, or position of a sprinter during
a race.
• analog signals are continuous and can take on an infinite possible values(the
real numbers)
• digital signals are finite. For example, 8-bit colors can take on one of 256
discrete, finite possibilities. But actual colors can take on any of an infinite
possible values or shades.
Digital vs. Analog
Analog data can be closely approximated digitally using a sampling technique,
which means measuring values of the analog signal at regular intervals called
samples.
The samples are measured to figure out the exact bits required to store each
sample. The number of samples measured per second is the sampling rate, the
higher the rate the better the quality.
31
Digital Audio Basics
32
Digital Audio Basics
• Sampling rate refers to
the number of times
per second that a
sound is measured
during the recording
process
• Higher sampling rates
increase the quality of
a sound recording but
require more storage
space
34
Digital Audio File Formats
•To play a digital audio file, you must use some type of
audio software, such as:
• Audio Software: General-purpose software and apps used for
recording, playing, and modifying audio files, such as iTunes
• Audio Players: Small standalone software application or
mobile app that offers tools for listening to digital audio and
managing playlists, typically included with your computer’s OS
(operating system)
• Audio Plugins: Software that works in conjunction with your
computer’s browser to manage and play audio from a Web page
37