280 likes | 282 Vues
Bits and Bytes. There are 10 types of people in this world: those that understand binary numbers, and those that don’t. . . . Bits and Binary Numbers. A bit is a B inary dig IT – a digit that can have two values: one or zero.
E N D
Bits and Bytes There are 10 types of people in this world: those that understand binary numbers, and those that don’t. . .
Bits and Binary Numbers • A bit is a Binary digIT – a digit that can have two values: one or zero. • Binary numbers are composed of bits, just like decimal numbers are composed of digits 0-9 • Binary numbers can be used to represent letters, numbers, pictures, sound, or just about anything. • The exact same pattern of 1s and 0s might represent many different things, depending on where it is and what program is using it. • For instance, the bits 01000010bcould represent the number 66, or the letter ‘A’, or part of a picture, or part of a sound, or. . . • The interpretation depends on the context. This includes things like the file extension, and the program that's reading the data. • What does coin mean?
Decimal Numbers and Place Value Base 10 is our old friend: 5473 = (5 * 1000) + (4 * 100) + (7 * 10) + (3 * 1) Can also be written as: (5 * 103) + (4 * 102) + (7 * 101) + (3 * 100) We could use any number as a base – 10 just happens to be convenient if you have 10 fingers.
Binary Numbers Base two only uses 0 and 1. The place values are powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, and so forth, ad infinitum. Example: 10010111b = (1*27) + (0*26) + (0*25) + (1*24) + (0*23) + (1*22) + (1*21) + (1*20) = 128 + 16 + 4 + 2 + 1 = 151
A Binary Odometer Binary: Decimal: And so on, ad infinitum. . .
Example Convert 198 to binary: 198 / 128 = 1, remainder is 70 70 / 64 = 1, remainder is 6 6 / 32 = 0, remainder = 6 6 / 16 = 0, remainer = 6 6 / 8 = 0, remainder = 6 6 / 4 = 1, remainder is 2 2 / 2 = 1, remainder is 0 0 / 1 = 0 198 = 11000110b
Bytes • A byte is 8 bits. 8 bits can represent 256 different values. • Computers generally use a byte or a series of bytes to represent information. • 16 bits will represent 256*256=65536 different values. • 24 bits will represent 256*256*256=16,777,216 different values. • and so on. . .
Hexadecimal – Base 16 4 bits: 16 different values • An 8 bit byte is frequently shown as a pair of hexadecimal (hex) digits. one byte 0110 1010 two hex digits: 0x6A Hex is widely used to represent colors in HTML tags: color=“#00FF0E” 6 hex digits are enough to specify 16.7 million different combinations of R,G,B
Decimal to Hex: • Convert decimal 173 to hex: • 173 / 16 = 10 (0xA), remainder = 13 (0xD) • 173 = 0xAD • Convert 0xBE to decimal: 0xBD = (11 * 16) + (14 * 1) 0xBE = 190 Hex to Decimal:
Binary to Hex Example D C 0xDC Starting from the right-most bit, break the binary number into groups of 4 bits, and convert each group to the equivalent hex digit.
Encoding Text • Fundamentally, computers just deal with numbers. They store letters and other characters by assigning a number for each one. Characters are generally represented in a computer as ASCII or Unicode values, where numbers are assigned to letters, digits, punctuation, etc. Sample ASCII:
What is Sound? Sound is variations in air pressure – air moving back and forth quickly. Your ear and your brain turn these variations in air pressure into sound.
How Do Speakers and Microphones Work? A speaker converts an electrical signal into movement of air, using magnets to push the air back and forth. When it pushes forward, the air is compressed. When it pulls back, the air is rarified, or decompressed. A microphone does the opposite – it converts the movement of air into an electrical signal.
Digital-to-Analog andAnalog-to-Digital Conversion Analog-to-digital Converter 01101001110. . Digital-to-analog Converter 01101001110. .
Digitization: Turning Sound into 1s and 0s Sampling: Converting analog information into a digital representation by measuring the value of the analog signal at regular intervals, and encoding these integer values in digital form – 1s and 0s. Sampling rate (or frequency):Howoften the measurements are taken. Sampling resolution:How many different values you quantize into. 8 bit resolution allows 256 different values, 16 bit resolution allows 65536 different values. Another way to look at it is, how many marks are there on your ruler? The finer the gradations, the more accurate the representation can be. Quantization error: The difference between the actual signal level and the integer value chosen to represent it
Turning Pictures into Numbers Original Image Divided into pixels Each pixel is averaged
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Turning Pictures into Numbers - 2 Palette: maps colors to numbers
Digitizing Gone Bad. . . Not enough colors in palette Resolution too low Original
A Possible Image File Format • An image file could be constructed like this: • First, include the palette of colors that are used • Second, give the height and width in pixels • Third, give the pixel data • More specifically, if the image used 256 different colors: • palette of 256 colors, each color 3 bytes: 768 bytes total • image width in pixels – 2 bytes • image height in pixels – 2 bytes • 1 byte for each pixel – indicates which of the 256 colors goes in that spot So an image that's 512 x 512 pixels would be: 768 + 2 + 2 + 262144 = 262916 bytes total
Run-Length Encoding There are many ways to compress a bitmapped image. One simple way is run-length encoding, which is effective if an image has a lot of consecutive pixels of the same color. The image is then expressed as a series of pairs, where each pair is a pixel color, and the number of pixels in a row of that color. For the image at left, it could be W, 20, B, 3, W, 1 ,B, 1, W, 11, B, 1, etc.
GIF and JPEG Compression • JPEG (Joint Photographic Experts Group) better for photos, images with complex color schemes • GIF (Graphics Interchange Format) better for line art, images with large areas of single color
Medical Imaging – the CAT Scan • The idea behind Computed Axial Tomography is to take X-rays from many different angles and use the information to construct an image of the object. We are essentially sampling the object with X-rays. • The elements in a 3D image are called voxels.
A Thought Experiment. . . • Imagine that you had a BB gun that always shot BBs at the same velocity, and you also had a radar gun that could measure the speed of a BB. . . • You take some measurements, and discover that different substances slow the BB down by different amounts: Substance (1 cm thick): BB Slows down by: hamburger 20 m/sec jello 15 m/sec slurpee 10 m/sec water 5 m/sec
100 m/sec 100 m/sec 100 m/sec 100 m/sec 70 m/sec 70 m/sec 75 m/sec 65 m/sec A Thought Experiment (cont) Slows down hamburger 20 m/sec jello 15 m/sec slurpee 10 m/sec water 5 m/sec B A C D each square is 1 cm2 – Can you determine what A, B, C, and D are?
Computed Axial Tomography • X-ray tube and detectors revolve around patient • Detectors measure intensity of X-rays after passing through the patient • Computer uses information to reconstruct a 3-D image