Tuesday, November 10, 2015
Tuesday, September 29, 2015
1.2.1 Bits, Bytes, and Data Abstraction
Unknown
11:27 AM
No comments
Activity 1.2.1 Bits, Bytes, and Data Abstraction
Introduction
Modern computers only use zeroes and ones for storing and processing data. How do computers produce pictures, video, and sound using only ones and zeroes?!
In this lesson you will develop programs on an Android™ device. Some of the data (namely, colors) will require the use of numbers that range from 0 to 255.
Why is 255 the largest number used? |
Part I. Binary numbers, the ASCII code, and magnetic storage
- Instead of the decimal number system, computers like the Android devices you'll use in the next activities store and process most numbers using the binary number system, which is base two.
The decimal number system you are familiar with uses ten digits, 0 through 9, and it has place values that are powers of 10.
We call this the base ten number system.
Example digits:
|
_9_
|
_0
|
_4
|
_7
| |
Place values:
|
10n
|
1000
|
100
|
10
|
1
|
Powers of ten:
|
10n
|
103
|
102
|
101
|
100
|
Explain why this sequence of digits 9047 represents “nine thousand forty seven.”
- A binary number is represented using only two digits: 0 and 1. A single zero or one is called a bit, just an abbreviation for “binary digit.” The place values in the binary number system are powers of 2. Fill out the chart below to find out what those place values are?
Example digits:
|
_1_
|
_0_
|
_1_
|
_1_
|
_1_
|
_0_
|
_1_
|
_1
| |
Place values:
|
128
|
64_
|
32_
|
16_
|
_ 8_
|
_4_
|
_2
|
1_
| |
Powers of 2:
|
2n
|
27_
|
26_
|
25_
|
_ 24
|
23_
|
_22
|
_21
|
_20
|
Bytes: 8 bits = 1 byte.
- The byte is a binary representation of a number between 0 and 255.
The place values of each bit within a byte are shown below.
In a list of 8 1’s or 0’s. Each digit store one bit— as a single zero or one.
For example, a byte with a value of 00010001 (in binary) represents the value 17 (in decimal) because the ones are in the 1s place and the 16s place. Since binary has only two digits, you can think of the place values with a 1 as being on and the place values with a 0 as being off.
- What is the decimal value of 00001111?15
- What is the binary representation for decimal value of 22?00010110
- Take a few moments to practice converting between binary and decimal representations using the Flash game at http://forums.cisco.com/CertCom/game/binary_game_page.htm
- The meaning of the value of a byte depends on what it represents. When you develop Android applications, you will represent colors, numbers, and characters. The number could be the red, green, and blue intensities of a color on the screen, or it could be the position of a speaker cone that generates sound. To represent letters, a common code is used: the ASCII code. To accommodate letters from other alphabets, usually we use the UTF-8 code. UTF-8 uses all the values from ASCII and then extends it with additional bytes to include other characters. The ASCII and UTF-8 codes are easy to find online. Here is part of that code:
Letter:
|
ASCII Code:
|
Binary:
|
Letter:
|
ASCII Code:
|
Binary:
| |
A
|
65
|
01000001
|
a
|
?
|
?
| |
B
|
66
|
01000010
|
b
|
98
|
?
| |
.
|
.
| |||||
D
|
?
|
?
|
.
| |||
.
|
.
| |||||
Z
|
90
|
?
|
z
|
122
|
1111010
|
Based on this table, what ASCII or UTF-8 value encodes for the character D? 68
How would you write that in binary?1000100
1. Use one of ASCII resources at the link below to translate the binary code below into ASCII characters.:
Binary Code: 01101001 01110100 00100111 01110011 00100000 00110100 00110010
ASCII Translation: ____it’s 42____
Part II. Images
- Bits can represent pictures as well as text. A graphic image is represented with pixels. For example, the sprites that you animated in Scratch™ programming language were all bitmapped images with distinct values associated with each pixel. You may choose to use such images again in App Inventor.
In one representational format (RGB, 3 bytes/pixel), the color of each pixel is stored by representing the intensity of red with the first byte, green with the second byte, and blue with the third byte. All color perception by humans can be represented by mixing these three colors of light. The diagram below shows the mixing needed to obtain secondary additive colors; these are different than the secondary subtractive colors you are familiar with. Magenta, for example, is a mixture of red and blue light and is represented by 255, 0, 255.
- What color is 255, 0, 0? red
- What color is 0, 255, 255? cyan
- Since yellow is red + green, it is represented by 255, 255, 0. The color can be made more greenish by reducing the red, such as 200, 255, 0. The color can be made dimmer by reducing all numbers, such as 100, 127, 0. What values would represent a very dark blue with a slightly reddish tint? 80, 0, 255
- Image files contain the RGB values for all pixels and meta-information like the author and date, data format, or camera settings. Most image formats also compress the data as described below. Ignoring meta-information and compression, the image file size is easy to calculate. A 200 x 300 pixel image with 3 bytes/pixel is 200 x 300 x 3 bytes = 180000 bytes = 180 kb.
What is the file size of an image that is 600 x 800 pixels with 3 bytes/pixel?
1440 kb
- Video is presented as a series of frames, each frame representing an image. One common standard (like MP4) to represent a movie uses 640 x 360 pixels for each frame and uses 24 frames/second. With 3 bytes/pixel, what is the file size of a 1 minute video?
16,588,800 kb
Part III. Data Compression
- Images and other files are often compressed to make the files smaller. This is the case with the APK source code files that you will send between your computer and your Android device. Compression is useful whenever you transfer data between devices or over a network because it reduces the amount of time that it takes to send and receive the file. One compression scheme takes advantage of repeated numbers:
1 1 1 2 2 2 2 2 2 7 6 is compressed to 3 1 6 2 1 7 1 6. The compressed format indicates that there are three 1s, six 2s, and so on.
- What is the compressed representation of 5 5 5 5 5 5 5 5 5 3 3 3? 9 5 3 3
- The compression ratio tells how much a file is shrunk by compression. There are two ways to report a compression ratio that are equally acceptable but not equivalent. One reports the percentage of the file size that can be eliminated; the other reports the ratio of uncompressed to compressed sizes. Either way, a higher compression ratio means more compression.
Percent Compression = 1 - Compressed File SizeUncompressed File Size
OR
Compression Ratio = Uncompressed File SizeCompressed File Size
If each number in the example is stored in one byte, then there are 11 bytes being compressed to 8 bytes.
The percent compression was 1 - 8/11 = 100% - 72% = 28%.
The compression ratio was 11/8 = 1.375:1. These are not equivalent, but both methods are used.
What percent compression was achieved in the example in part a? What compression ratio? 1-4/12=100%-33%=66%
12/4= 3:1
- The compression method in question 11 was lossless. The resulting data was more compactly represented, but all information is still there. Most compression algorithms (like JPG) are lossy, meaning that some information has been left out or lost and the original data cannot be re-created from the compressed data. One lossy compression method uses a limited color palette so that the color of each pixel can be specified with fewer than 3 bytes. This method will create large blocks of uniform color, losing the slight variations in the original image.
- The greater the lossiness, the smaller the file (good) but the lower the fidelity (potentially bad). For images and video, low fidelity means low quality. Companies transmitting via Internet have to balance quality of the video against quality of the transmission speed. Think of an Internet video you have seen and decide whether you would prefer higher fidelity or higher transmission speed and explain why.
High quality, because you can just give it time to load which means a better video.
- In videoconferencing software, face detection algorithms are used to identify portions of each frame where lower compression ratios should be used: the portions containing faces. Explain the benefits of using this algorithm in terms of both fidelity and speed.
This means you can have a clear face and a foggy surrounding but the quality of your speed increases because of the slight loss in background, which doesn’t matter anyways when you’re in a video conference
Part IV. Connection to Society and the Analog/Digital Distinction
There are many examples of software failures throughout history. Knowing how and why some of these errors occur will help you to develop more functional applications.
In 1996 the European Space Agency had to detonate an Ariane 5 rocket and its spacecraft payload because of software design. In its guidance software, a 64-bit number representing acceleration was truncated to a 16-bit number. The software was inherited from the Ariane 4 rocket, which didn’t accelerate as much. For more information, see http://en.wikipedia.org/wiki/Ariane_5#Notable_launches .
What is the maximum value for a 64-bit number?
What is the maximum value for a 16-bit number?
Hint: Your answer depends on how the bits represent the number.
Reduced fractions are repeating decimals if their denominator (when the fraction is reduced) has prime factors other than 2 and 5. This is because only 2 and 5 are the prime factors of the base 10.
In 1991 the U.S. Patriot missiles were unsuccessfully used against SCUD missiles in the U.S.-Iraq war. Among the causes was a software design flaw related to a timer for sending radar detection bursts. The timer was incremented in 0.1 second increments, with the accumulated value stored in – of course – binary. Because 1/10 has a denominator with prime factors other than 2, this is a repeating binary number. The software truncated the representation, and the small error accumulated over hours of operation. The U.S. Army was notified of the design flaw and instructed soldiers to keep the Patriot missiles off unless being deployed. One set of soldiers, however, left the Patriot launcher powered on, and its timer accumulated an error of 0.3 second. This caused a failure to track a SCUD missile, and the missile killed 28 soldiers when it struck U.S. barracks.
|
- Give examples of rational numbers between 0 and 1 that can be represented as decimal without repeating and other examples that repeat.
⅓,and 1/9
- Give examples of rational numbers between 0 and 1 that can be represented in binary without repeating and other examples that repeat.
1/2
- The acceleration and time mentioned in the previous two examples are continuous quantities: instead of jumping from one value to another, continuous quantities vary smoothly, having all intermediate values along the way. Continuous values can only be represented by analog data. Analog data stores all possible continuous values within a range, like a needle on a meter.
The opposite of continuous is discrete. Discrete quantities jump from one value to another without ever equaling the values in between. Discrete value is represented by digital data. Digital data can only have specific values within a range. The examples illustrate why using digital data to describe analog quantities can be problematic.
Physical quantities like acceleration and time are often continuous quantities. The sounds that we experience, including music, are actually air pressure quickly increasing and decreasing. Air pressure is continuous, and analog recordings like vinyl records or cassette tape represent sound using continuous data like vinyl thickness or magnetic field strength.
With the widespread release of audio CDs in 1983, the music industry began a fast transition from analog to digital. The figure at right shows analog-to-digital conversion from analog (red) to 4-bit digital (gray). How you can tell that the digital representation requires 4 bits per pressure level?
Follows the other curve
|
- When we convert continuous quantities to digital data, we lose information. However, digital data have huge advantages. Digital measurements can often collect data with higher precision, and digital data can be copied over and over without errors accumulating. Digital data can also be duplicated and distributed at very low cost. Does this encourage or inhibit society’s production and distribution of music and more generally creative ideas and expression? It is a controversial issue. Try to make the case for each side of this issue.
Anyone can get their hands on anything, it makes sharing easier in good and bad ways, while it adds availability of sharing things you create yourself, you can also share things that aren’t yours (illegal)
Part V. Data Abstraction
- When a computer program stores data, it usually also stores the type of data so that the computer knows what the zeroes and ones represent. A programmer often wants to name a color for a pixel, for example, without worrying about how the color is represented in zeroes and ones, and certainly without worrying about the magnetic, optical, or electronic phenomena representing the zeroes and ones. As a computer user, you have probably moved image files from one place to another without knowing anything about the individual pixels in the image. The image is stored using details stacked one level on top of another: details about magnetic fields, 0s and 1s, pixels, and compression. Separating the different levels of detail representing data is called data abstraction.
- Describe the data abstraction that might be associated with the data in an audio file.
helps you know it’s an audio file
- Explain why computers and computation wouldn’t be practical without data abstraction.
then you wouldn’t know what’s what.
Conclusion
- Describe information that can be represented by zeroes and ones.
binary, anything
- What is the relationship among data compression, data transmission speed, and fidelity vs. lossiness?
they all determine how well something works.
- Consider the music produced by a band. Describe how both the terms “digital” and “analog” can be applied to the music produced and recorded by a band.
analog music is recorded, like a record or a phonograph while digital music is discrete numbers
Subscribe to:
Posts (Atom)