1 / 20

Binary (Base-2) Numbers

1. 1. 1. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0. Binary (Base-2) Numbers. Information may be reduced to its fundamental state by means of binary numbers (e.g., on/off, true/false, yes/no, high/low, positive/negative).

tfontenot
Download Presentation

Binary (Base-2) Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1 1 1 1 1 1 0 0 0 0 0 0 0 Binary (Base-2) Numbers • Information may be reduced to its fundamental state by means of binary numbers (e.g., on/off, true/false, yes/no, high/low, positive/negative). • “Bits” (binary digits) are used to accomplish this. Normally, we consider a binary value of 1 to represent a “high” state, while a binary value of 0 represents a “low” state. • In machines, these values are represented electronically by high and low voltages, and magnetically by positive and negative polarities. Chapter 1 – Data Storage

  2. Binary Numerical Expressions • Binary expressions with multiple digits may be viewed in the same way that multi-digit decimal numbers are viewed, except in base 2 instead of base 10. • For example, just as the decimal number 275 is viewed as 5 ones, 7 tens, and 2 hundreds combined, the binary number 01010110 can be viewed in right-to-left fashion as... 01010110 01010110 01010110 01010110 01010110 01010110 01010110 01010110 01010110 01010110 • 0 ones So, 01010110 is equivalent to the decimal number 2 + 4 + 16 + 64 = 86 • 1 two • 1 four • 0 eights • 1 sixteen • 0 thirty-twos • 1 sixty-four • 0 one hundred twenty-eights Chapter 1 – Data Storage

  3. Binary Code Binary Code Hexadecimal Notation Hexadecimal Notation 1000 0000 0 8 1001 0001 1 9 0010 1010 A 2 0011 1011 B 3 0100 1100 4 C 0101 1101 5 D 1110 0110 E 6 0111 1111 F 7 Hexadecimal (Base-16) Notation • As a shorthand way of writing lengthy binary codes, computer scientists often use hexadecimal notation. For example, the binary expression 1011001011101000 may be written in hexadecimal notation as B2E8. The two expressions mean the same thing, but they are in different notations. Chapter 1 – Data Storage

  4. ASCII: American Standard Code for Information Interchange 0000000 NUL (null) 0100000 SPACE 1000000 @ 1100000 ` 0000001 SOH (start of heading) 0100001 ! 1000001 A 1100001 a 0000010 STX (start of text) 0100010 " 1000010 B 1100010 b 0000011 ETX (end of text) 0100011 # 1000011 C 1100011 c 0000100 EOT (end of transmission) 0100100 $ 1000100 D 1100100 d 0000101 ENQ (enquiry) 0100101 % 1000101 E 1100101 e 0000110 ACK (acknowledge) 0100110 & 1000110 F 1100110 f 0000111 BEL (bell) 0100111 ' 1000111 G 1100111 g 0001000 BS (backspace) 0101000 ( 1001000 H 1101000 h 0001001 TAB (horizontal tab) 0101001 ) 1001001 I 1101001 i 0001010 LF (NL line feed, new line) 0101010 * 1001010 J 1101010 j 0001011 VT (vertical tab) 0101011 + 1001011 K 1101011 k 0001100 FF (NP form feed, new page) 0101100 , 1001100 L 1101100 l 0001101 CR (carriage return) 0101101 - 1001101 M 1101101 m 0001110 SO (shift out) 0101110 . 1001110 N 1101110 n 0001111 SI (shift in) 0101111 / 1001111 O 1101111 o 0010000 DLE (data link escape) 0110000 0 1010000 P 1110000 p 0010001 DC1 (device control 1) 0110001 1 1010001 Q 1110001 q 0010010 DC2 (device control 2) 0110010 2 1010010 R 1110010 r 0010011 DC3 (device control 3) 0110011 3 1010011 S 1110011 s 0010100 DC4 (device control 4) 0110100 4 1010100 T 1110100 t 0010101 NAK (negative acknowledge) 0110101 5 1010101 U 1110101 u 0010110 SYN (synchronous idle) 0110110 6 1010110 V 1110110 v 0010111 ETB (end of trans. block) 0110111 7 1010111 W 1110111 w 0011000 CAN (cancel) 0111000 8 1011000 X 1111000 x 0011001 EM (end of medium) 0111001 9 1011001 Y 1111001 y 0011010 SUB (substitute) 0111010 : 1011010 Z 1111010 z 0011011 ESC (escape) 0111011 ; 1011011 [ 1111011 { 0011100 FS (file separator) 0111100 < 1011100 \ 1111100 | 0011101 GS (group separator) 0111101 = 1011101 ] 1111101 } 0011110 RS (record separator) 0111110 > 1011110 ^ 1111110 ~ 0011111 US (unit separator) 0111111 ? 1011111 _ 1111111 DEL • ASCII code was developed as a means of converting text into a binary notation. • Each character has a 7-bit representation. • For example, CAT would be represented by the bits: 100001110000011010100 Chapter 1 – Data Storage

  5. 64 11011000000111 128 10010000011001000 192 010111000011001001 256 0110111000001011011 320 00110110000000110011 384 00110111000000110100 448 01100100000000110101 512 011001010000001101100 576 01101000 0000001101101 640 01100111 0000001001010 704 0110011000000001001011 768 0110011010000001001100 832 0110100100000001001101 896 0110100110000001110010 960 0110101000000001110011 1024 0110101010000001110100 1088 0110101100000001110101 1152 011010111 0000001110110 1216 0110110000000001110111 1280 011011001 0000001010010 1344 0110110100000001010011 1408 011011011 0000001010100 1472 010011000 0000001010101 1536 010011001 0000001011010 1600 010011010 0000001011011 1664 0110000000001100100 1728 010011011 0000001100101 1792 00000001000 00000001000 1856 0000000110000000001100 1920 00000001101 00000001101 1984 000000010010000000010010 2048 000000010011000000010011 2112 000000010100000000010100 2176 000000010101000000010101 2240 000000010110000000010110 2304 000000010111000000010111 2368 000000011100000000011100 2432 000000011101000000011101 2496 000000011110000000011110 2560 000000011111000000011111 CCITT: Fax Conversion Code • Fax machines use binary code to represent the white and black spans on each ultra-thin scanline of a page. length whiteblack 0 001101010000110111 1 000111010 2 011111 3 100010 4 1011011 5 11000011 6 11100010 7 111100011 8 10011000101 9 10100000100 10 001110000100 11 010000000101 12 0010000000111 13 00001100000100 14 11010000000111 15 110101000011000 16 1010100000010111 17 1010110000011000 18 01001110000001000 19 00011000000100111 20 000100000001101000 21 001011100001101100 22 000001100000110111 23 000001100000101000 24 010100000000010111 25 010101100000011000 26 0010011000011001010 27 0100100000011001011 28 0011000000011001100 29 00000010000011001101 30 00000011000001101000 31 00011010000001101001 length whiteblack 32 00011011000001101010 33 00010010000001101011 34 00010011000011010010 35 00010100000011010011 36 00010101000011010100 37 00010110000011010101 38 00010111000011010110 39 00101000000011010111 40 00101001000001101100 41 00101010000001101101 42 00101011000011011010 43 00101100000011011011 44 00101101000001010100 45 00000100000001010101 46 00000101000001010110 47 00001010000001010111 48 00001011000001100100 49 01010010000001100101 50 01010011000001010010 51 01010100000001010011 52 01010101000000100100 53 00100100000000110111 54 00100101000000111000 55 01011000000000100111 56 01011001000000101000 57 01011010000001011000 58 01011011000001011001 59 01001010000000101011 60 01001011000000101100 61 00110010000001011010 62 00110011000001100110 63 00110100000001100111 Chapter 1 – Data Storage

  6. Binary Code Interpretation How is the following binary code interpreted? 10100111101111010000011001011100001111001111110010101110 In “programmer’s shorthand” (hexadecimal notation)… 1111 1100 1010 0111 1011 1101 0000 0110 0101 1100 0011 1100 1010 1110 F C A 7 B D 0 6 5 C 3 C A E As ASCII text… 1010011 1101111 0100000 1100101 1100001 1110011 1111001 0101100 S o (space) e a s y . As CCITT fax conversion code… 10100 9 white 11 2 black 11011 64 white 110100 14 white 00011 7 black 0010111 21 white 0000111 12 black 10011 6 white 11 2 black 1100 5 white 10 3 black 1011 4 white 10 3 black Chapter 1 – Data Storage

  7. Data Storage: Main Memory • Whenever a computer accesses information (e.g., a program that’s being executed, data that’s being examined), that information is stored as electronic pulses within main memory. • Main memory is a system of electronic circuits known as random access memory (RAM), the idea being that the user can randomly access any part of memory (as long as the location of what’s being accessed is known). • The circuitry in main memory is usually dynamic RAM, meaning that the binary values must be continuously refreshed (thousands of times per second) or the charge will dissipate and the values will be lost. Chapter 1 – Data Storage

  8. Data Output Enable NAND NAND NAND NAND NOT Data Storage: Cache Memory • Due to the need for continuous refreshing, dynamic RAM is rather slow. An alternative approach is static RAM, which uses “flip-flop” circuitry that doesn’t waste time refreshing the stored binary values. When Enable has a 1 value, the new Data value becomes the Output value. When Enable has a 0 value, the old Data value is retained as the Output value. • Static RAM is much faster than dynamic RAM, but is much more expensive. Consequently, it is used less in most machines. • Cache memory uses static RAM as the first place to look for information and as the place to store the information that was most recently accessed (e.g., the current program being executed). Chapter 1 – Data Storage

  9. Data Storage: Magnetic Disks • When the power is turned off, a computer’s electronic memory devices immediately lose their data. In order to store information on a computer when it’s turned off, some non-magnetic storage capability is required. • Most computers contain hard drives, a system of magnetic platters and read-write heads that detect the polarity of the magnetic filaments beneath them (i.e., “reading” the bit values) and induce a magnetic field onto the filaments (i.e., “writing” the bit values). Chapter 1 – Data Storage

  10. Data Storage: Tracks & Sectors • Each platter is divided into concentric circles, called tracks, and each track is divided into wedges, called sectors. • The read-write head moves radially towards and away from the center of the platter until it reaches the right track. • The disk spins around until the read-write head reaches the appropriate sector. Chapter 1 – Data Storage

  11. Data Storage: Floppy Disks • Portable magnetic memory devices, known as floppy disks, have limited storage capacity, slow revolution speeds, and long access times, but they are easily removed from a machine and installed in another computer. Chapter 1 – Data Storage

  12. Data Storage: CD-ROMs & DVDs • Compact Disks – Read-Only Memory (CD-ROMs) use pitted disks and lasers to store binary information. • When the laser hits an unpitted “land”, light is reflected to a sensor and interpreted as a 1-bit; when the laser hits a pit, light isn’t reflected back, so it’s interpreted as a 0-bit. • Digital Versatile Disks (DVDs) use the same pits-and-lands approach as CD-ROMs, but with finer gaps between tracks and pits, resulting in over four times the storage capacity as CD-ROMs. Chapter 1 – Data Storage

  13. 4-Bit Pattern Integer Value 4-Bit Pattern Integer Value 0000 0 1000 -8 0001 1 1001 -7 0010 2 1010 -6 0011 3 1011 -5 0100 4 1100 -4 0101 5 1101 -3 0110 6 1110 -2 0111 7 1111 -1 Digital Integers: Two’s Complement Notation • Two’s complement notation was established to ensure that addition between positive and negative integers shall follow the logical pattern. For example… 1101 + 0011 = 0000 (i.e., -3 + 3 = 0) 0011 + 0010 = 0101 (i.e., 3 + 2 = 5) 1100 + 1101 = 1001 (i.e., -4 + -3 = -7) 0110 + 0011 = 1001 (i.e., 6 + 3 = -7???) OVERFLOW!!! 1001 + 1110 = 0111 (i.e., -7 + -2 = 7???) OVERFLOW!!! Chapter 1 – Data Storage

  14. Coding & Decoding in Two’s Complement Notation • How do we code –42 in two’s complement notation using 8 bits? • First, write the value 42 in binary: 00101010 • Next, complement each bit: 11010101 • Finally, add one: 11010110 (This is –42) • How do we decode 10110100 from two’s complement into an integer? • First, subtract one from 10110100: 10110011 • Next, complement each bit: 01001100 • Finally, convert the positive integer: 76 • So, the original integer was –76 Chapter 1 – Data Storage

  15. Digital Fractions: Floating-Point Notation • When representing a fractional number like 17.15 in binary form, a rather complicated approach is taken. • Using only powers of two, we note that 17 is 24 + 20 and .15 is 2-3 + 2-6 + 2-7 + 2-10 + 2-11 + 2-14 + 2-15 + 2-18 + 2-19 + 2-22 + … • So, in pure binary form, 17.15 would be 10001.0010011001100110011001… • In “scientific notation”, this would be 1.0001001001100110011001… × 24 • The standard for floating-point notation is to use 32 bits. The first bit is a sign bit (0 for positive, 1 for negative). The next eight are a bias-127 exponent (i.e., 127 + the actual exponent). And the last 23 bits are the mantissa (i.e., the exponent-less scientific notation value, without the leading 1). • So, 17.15 would have the following floating-point notation: 0 10000011 00010010011001100110011 Chapter 1 – Data Storage

  16. Data Compression: Audio • To compress large audio files down to manageable sizes, the audio is sampled thousands of times per second and then “quantized” (i.e., rounded off to one of several discrete values). Chapter 1 – Data Storage

  17. Original File: 326321 bytes Compressed File: 9438 bytes Data Compression: Images • To compress large image files, we take advantage of the fact that images usually have little color variation from pixel to adjacent pixel. • For example, JPEG (the Joint Photographic Experts Group) uses a complex scheme that breaks pictures down into small 8x8 blocks of pixels, looks for color patterns within each block, and then merely codes which patterns come closest to the image’s blocks. Chapter 1 – Data Storage

  18. Data Compression: Video • Just as image compression takes advantage of the similarity between adjacent pixels, video compression takes advantage of the similarity between consecutive video frames. • For example, MPEG (the Moving Picture Experts Group) uses intra-coded pictures (frames of actual picture data), predictive pictures (frames that are generated by predicting from previous I-frames and P-frames), and bidirectional pictures (frames that are generated by blending between previous and future I-frames and P-frames). • By only coding the differences between frames, the P-frames and B-frames use very few bits. I B B B P B B B P B B B P Chapter 1 – Data Storage

  19. Communication Errors: Parity Bits • When data is transmitted across communication networks or from storage devices, it’s possible that some of that data will be “corrupted” and certain bit values will be misinterpreted. • One way to detect such errors is by using parity bits to ensure that each segment of data has an even number of 1’s (even parity) or an odd number of 1’s (odd parity), depending on which type of parity the system is using. Wants to send message “YO!” in ASCII, using even parity. ASCII ‘Y’ is 1011001, so tack on a ___ ASCII ‘O’ is 1001111, so tack on a ___ ASCII ‘!’ is 0010001, so tack on a ___ 0 Received message is: 10110010 10011111 00110010 First byte is 10110010, with even parity, so it’s ASCII ‘Y’ Second byte is 10011111, with even parity, so it’s ASCII ‘O’ Third byte is 00110010, with odd parity, so it’s an error!!! 1 0 So, the transmitted message is: 10110010 10011111 00100010 Networked Machine Networked Machine 101100101001111100100010 • One major problem with parity bits: if a data segment has an even number of corrupted bits, then no error is detected! Chapter 1 – Data Storage

  20. 1 1110010000100111 11100100001001 111001000010011111 11 111001000010011 111 111001 11100100001001111 11100100001 110101 10001101100100011110011 110101 101100 110101 110011 110101 00110100 110101 0000110001 110101 00100111 110101 100100 110101 100010 110101 101111 110101 110101 110101 00000 Communication Errors: Cyclic Redundancy Check For more effective error detection, the cyclic redundancy check was devised. 1. Both stations agree upon a binary “generator”, for example: 110101 4. The receiving station performs a modulo-2 division by the generator on the received message (including the appended CRC suffix). 1 111001 11100100001001111 1110010000100111 111001000010011111 111001000010011 11100100001001 11 11100100001 111 110101 10001101100100011100000 110101 2. The sending station tacks len(generator)-1 0’s onto its binary message and does a modulo-2 division by the generator. For example, if the original message is 100011011001000111 with generator 110101, then the division at left is performed. 101100 110101 110011 110101 00110100 110101 0000110001 110101 00100110 110101 5. If the remainder of this quotient is non-zero, then a transmission error has occurred. Otherwise, we’re reasonably certain that there’s been no error! 100110 110101 100110 110101 100110 110101 100110 3. The sending station transmits its message, with the remainder of the above quotient added as a suffix. 110101 10011 Actual transmission:10001101100100011110011 Chapter 1 – Data Storage

More Related