Presentation on theme: "Bits and Bytes There are 10 types of people in this world: those that understand binary numbers, and those that don’t. . . We’ve talked a lot about how."— Presentation transcript:
1Bits and BytesThere are 10 types of people in this world: those that understand binary numbers, and those that don’t. . .We’ve talked a lot about how computers work so far. Let’s recap a little – what have we talked about so far in this class? (hardware, booting, OS, XP, viruses) Well, the whole thing turns out to be a very complicated system for fiddling with ones and zeroes. It turns out that you can do a whole lot with ones and zeroes. Words, pictures, sounds, movies – can all be turned into numbers. And anything you can turn into a number, you can turn into ones and zeroes.Two values instead of our decimal digits, which can have 10A switch has two states – on and off. Computer memory is basically made up of switches -- easy to represent 1s and 0s.But nobody is very interested in a blob of 1s and 0s – need to assemble them into larger and more interesting things.How do we use 1s and 0s to represent numbers? Words? Music? Pictures? Movies?
2Bits 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-9Binary 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 b could 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?coin – money in english, corner in french
3Decimal 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)Why do we use base 10? Because we have 10 fingers (what do the Simpsons use?)10 is the radix – a fancy name for the base of a number system.You need 10 different symbols to represent the values in base 10. We use the digits 0-9The rest of the meaning is conveyed by place – the 1s, 10s, 100s, etc.We could use any number as a base – 10 just happens to be convenient if you have 10 fingers.
4Binary NumbersBase 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: b= (1*27) + (0*26) + (0*25) + (1*24) + (0*23) + (1*22) + (1*21) + (1*20)=128's64's32's16's8's4's2's1's1= 151
5A Binary Odometer Binary: Decimal: And so on, ad infinitum. . . 1 1 2 110's1's123456789have kids with 1/0 paper – count 0 – 32go around room from thereAnd so on, ad infinitum. . .
7Bytes 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. . .How many different values can be represented in 16 bits? 256 * 256 = 65536Why 8 bits in a byte? Like asking why is 12 a dozen. Just something that worked out well over the years.Really became set in stone with IBM 360 computers in 1965
8Counting Bytes: Kilo, Mega, Giga, Tera, and Lotta PrefixApproximately?Abbrev.Exactly?How many bytes?KiloThousand (103)KB1024MegaMillion (106)MB1024 KB1,048,576GigaBillion (109)GB1024 MB1,073,741,824TeraTrillion(1012)TB1024 GB1,099,511,627,776PetaQuadrillion (1015)PB1024 TB1,125,899,906,842,624ExaQuintillion (1018)EB1024 PBA whole lot. . .ZettaSextillion (1021)ZB1024 EBEven more. . .YottaSeptillion (1024)YB1024 ZBFuggedabaddit. . .Giga comes from greek work gigas, for giantTera comes from greek word teras, for monsterA typical video store contains about 8 terabytes of video (Wikipedia)San Diego Supercomputer Center has a petabyte of hard disk storage and 6 petabytes of tape storageThere are about 7 sextillion grains of sand on all the worlds deserts and beachesIf you had a 1 kbps connection to the internet, how long would it take to transmit 1 KB of data?When you talk about speed,you talk about Bits per second, and 1 Kb isn’t 1024 bits, its So 1 KB = 1024 * 8 = 8192Would take seconds to send 1KBIf you have 20 people waiting in line at a bank, and the tellers can handle 2 people per minute, how long will it take to handle the line?
9Hexadecimal – Base 16An 8 bit byte is frequently shown as a pair of hexadecimal (hex) digits.4 bits: 16 different valuesdecbinhex0000b0x081000b0x810001b0x191001b0x920010b0x2101010b0xA30011b0x3111011b0xB40100b0x4121100b0xC50101b0x5131101b0xD60110b0x6141110b0xE70111b0x7151111b0xFone bytetwo hex digits:0x6AHex 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
10Decimal to Hex: Hex to Decimal: Convert decimal 173 to hex:173 / 16 = 10 (0xA), remainder = 13 (0xD)173 = 0xAD16's1'sADHex to Decimal:Convert 0xBE to decimal:0xBD = (11 * 16) + (14 * 1)0xBE = 19016's1'sBE
11Binary to Hex Example 0xDC 1 D C 128's64's32's16's8's4's2's1's1DC0xDCStarting from the right-most bit, break the binary number into groups of 4 bits, and convert each group to the equivalent hex digit.
12Encoding TextFundamentally, 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.BinaryDecimalSymbol48491502…65A66B67CSample ASCII:The idea is the same as if you made up a code that says that 1 = a, 2 = b, etcNote anything interesting?Digits map to lower 4 bitsUpper case, lower case 1 bit different for alphabetizationWhat about non-western languages? Unicode – 16 bits allows 64K symbols – when upper byte 0, lower byte treated as if ASCII
13Analog DigitalWe saw yesterday how you could express any number in terms of 1s and 0s – so that means if we can express anything as numbers, we can express it as 1s and 0s.So now the question is, how do we express things in terms of numbers?The analog clock is continuous. It can’t get from 1:00 to 1:01 without passing through every point between the two. It can display an infinite number of points, even if you can’t see them all. If you used a magnifying glass, you’d see it sweep past every point – it can’t skip over anythingThe digital clock is an approximation of the time. It goes directly from 1:00 to 1:01 – there is no in-between. (draw step graph on board)You can continue to add digits – seconds, tenths, etc – the more digits, the closer you can get. But you always lose a little information.The values are discrete – you can count how many different values it can display.An analog clock can display an infinite number of values, even if you can't see them. It's the hands that tell the time, not the numbers.shows minutes – 0-23, 0-59 – 24 * 60 -> 1440 minutes per day, sec
14What 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.Can think of sound as sculpting the airIs it discrete or continuous?
15How 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.So, now we’ve gotten sound into electricity (mike) and electricity into sound (speaker)The electrical signal from a mike is still continuous -- we haven’t gotten it into 1s and 0s yetHow a speaker works:windings of wire around iron core – pass current through, 1 end will be NNear another magnet – will be attracted or repulsed – switch current direction, magnet polarity reversed, switches attraction/repulsion
16Digital-to-Analog and Analog-to-Digital Conversion ConverterAnalog to digital converter: converts a continuous signal into a sequence of discrete values-> takes frequent measurementsdigital to analog converter: converts a sequence of discrete values into a continuous signalIn-between – series of numbers – can save it on a disk, copy it, it, etcDigital-to-analogConverter
17Digitization: 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): How often the measurements are taken.Sampling resolution: How many different values you quantize into. 8 bit resolution allows 256 different values, 16 bit resolution allows 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 ithave to turn the continuous range into a set of discrete values, like the digital clock – there's no "in-between", we have to pick one of the values on the Y axis to represent the continuous value at that point.The more often you take measurements and the more precise the measurements are (note Y axis), the closer the digitized version is to the original, and the bigger the file is. . .Frequency: how often you measureResolution: how many different values you have to represent the heightThe middle graph resolves the sample into one of ten values 0 – 9The bottom graph resolves the sample into one of 36 valuesYou have to decide how good is good enough – voice quality is not the same as music qualitySo, once you’ve gotten it into 1s and 0s, what can you do? Mail it, copy it, play it backwards, correct the pitch, etc – we'll see with AudacityCopy is identical to the original – it’s just a numberYou lose some quality when you digitize something, but once it’s digital, you won’t lose any more no matter how many copies you makeit's a number – and a copy of the number is the same numberCompare to a “tape of a tape of a tape”Clipping and distortion –given the bottom graph, what if a sound wave comes along that's twice as high as what's there? You don't have the range to represent it – so it gets distorted – a.k.a. clipping -- "dial goes into the red" in the recording studiodynamic range – the range of volume levels that the digitization scheme can accomodate
19Turning Pictures into Numbers Pixel stands for “picture element”Pixel should be pickle?Lay out grid over pictureA pixel is a single colored dot – can’t have two colors in the same pixelDecide what color best represents that squareEncode color as a numberThe finer the grid and the more colors you use, the better the image – and the larger the digital version.Audio sampling rate -> how fine the grid is, or how many pixels (dpi)Original ImageDivided into pixelsEach pixel is averaged
20Turning Pictures into Numbers - 2 Audio sampling resolution -> # of colors in palette, or color depthPalette: maps colors to numbers
21Digitizing Gone Bad. . . Not enough colors Resolution too low Original in paletteResolution too lowOriginal
22A Possible Image File Format An image file could be constructed like this:First, include the palette of colors that are usedSecond, give the height and width in pixelsThird, give the pixel dataMore specifically, if the image used 256 different colors:palette of 256 colors, each color 3 bytes: 768 bytes totalimage width in pixels – 2 bytesimage height in pixels – 2 bytes1 byte for each pixel – indicates which of the 256 colors goes in that spotSo an image that's 512 x 512 pixels would be:= bytes totalThink of the palette as the possible colors of all the tiles we're going to useDifferent images can use different palettespicking the best range of colors to represent the image is one of the challenges
23Run-Length EncodingThere 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.16 x 16 = 256 bytes uncompressed76 runs, 76*2 bytes = 152 bytes
24GIF and JPEG Compression JPEG (Joint Photographic Experts Group) better for photos, images with complex color schemesGIF (Graphics Interchange Format) better for line art, images with large areas of single colorCompression:Since each color takes 24 bits (3 bytes), a 400x400 pixel image would be 480,000 bytesJPEG – Joint Photographic Experts GroupJPEG – better for photos, more complex images – continuous tone. Not good for line artGIF – better for line art, images with large areas of single colorGIF – limited to 256 different colors.JPEG – full color information (24 bits per pixel) – much more complex technique for reducing designed to exploit known limitations of the human eye, notably the fact that small color changes are perceived less accurately than small changes in brightness. Makes images smaller by throwing away some info – “lossy” compressionGIFs can also have transparent areas, animation(So how do you encode movies?)Need to find out about PNG
25Medical 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.
26A 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/secjello m/secslurpee m/secwater 5 m/sec
27A Thought Experiment (cont) Slows downhamburger 20 m/secjello 15 m/secslurpee 10 m/secwater 5 m/sec100 m/sec100 m/sec100 m/secB70 m/secA100 m/secCD70 m/secA is slurpee, B is hamburgerC,D are jelloOr A, B are jelloC is slurpee, D is hamburgerWhat if you took another shot through C, B and A, D? Not 1 cm distance any more. . .If first solution: AD would be 75, CB would be 65IF second solution: AD would be 65, CB would be 75each square is 1 cm2 –Can you determine whatA, B, C, and D are?75 m/sec65 m/sec
28Computed Axial Tomography X-ray tube and detectors revolve around patientDetectors measure intensity of X-rays after passing through the patientComputer uses information to reconstruct a 3-D image