Bits, Nybbles, Bytes, numbers and characters Brian Mapes MPO581 Jan 24, 2011 from googling and poaching
Data Types bit - a 0 or 1. Can represent 2 unique values byte - 8 bits. 256 values -128 to 128 unsigned byte - 8 bits 0 to 256 character – an alphabet-mapped byte short int - 16 bits -32767 to 32767 long int – 32 bits 4,294,967,296 values float - 32 bits coded: mantissa,exp double - 64 bits coded word – machine dependent. 32 or 64 bits
Binary Equivalents of Decimal Numbers Decimal Binary (LR) Binary (R L) 0 0000 0000 1 0001 1000 2 0010 0100 3 0011 1100 4 0100 etc. 5 0101 6 0100 7 0111 8 1000 Is “most significant bit” (MSB) at “right” or “left”? (right and left are arbitraryin computer chip memory space)
Powers of 2 Decimal Decimal 20 1 28 256 21 2 29 512 22 4 210 1024 20 1 28 256 21 2 29 512 22 4 210 1024 23 8 211 2048 24 16 212 4096 25 32 213 8192 26 64 214 16384 27 128 215 32768
Decimal (base 10) numbers A decimal number can be represented as the sum of powers of 10 (the base) with coefficients in the base 10 alphabet (0 - 9) For example: 2485 = 2000 + 400 + 80 + 5 2485 = 2 * 1000 + 4 * 100 + 8 * 10 + 5 * 1 2485 = 2 * 103 + 4 * 102 + 8 * 101 + 5 * 100 Same principle can be applied in binary...
Hexadecimal Numbers (nybbles or half-bytes) 4 bits Base-16 number system Uses digits 0 - 9 and letters A - F One hexadecimal digit can express values from 0 to 15 For example: C represents 12 (Not important for us - Used in memory addressing, sometimes wifi passwords,...)
Hexadecimal - Binary Equivalents Hex Binary Hex Binary 0 0000 8 1000 1 0001 9 1001 2 0010 A 1010 3 0011 B 1011 4 0100 C 1100 5 0101 D 1101 6 0110 E 1110 7 0111 F 1111
Characters and strings EBCDIC, Extended Binary Coded Decimal Interchange Code Used by IBM in mainframes (360 architecture and descendants). Earliest system ASCII, American Standard Code for Information Interchange. Most common system Unicode, http://www.unicode.org New international standard Variable length encoding scheme with either 8- or 16-bit minimum “a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.” EBCDIC - 8 bit ASCII - 7 bit, 128 characters EBCDIC - Extended Binary Coded Decimal Interchange Code Unicode - uses a default 16-bit encoding, but includes extensions that permit over 900,000 additional characters. It offers two Unicode Transformation Formats, UTF-8 and UTF-16, variable length encoding schemes with, respectively, 8- and 16-bit minimum length codes. UTF-8 is compatible with ASCII. CSE360
The Unicode Character Set Each character stored as 16-bits Maximum number of characters that can be represented: 65,536 (216) ASCII character set (used by many programming languages) stores each character as 7 bits (maximum number of characters is 128). For compatibility, first 128 characters of Unicode set represent the ASCII characters
Some Unicode Characters Unicode Character Decimal Value * 42 1 49 2 50 A 65 B 66 a 97 b 98 } 125
Bytes as the “element” of data Memory: Can be viewed as an array of storage elements. The index of each element is called the address. Each element holds the same number of bits. How many bits per element? 8, 16, 32, 64? 8 (Byte) is typical Words are about the processor: how many bytes are loaded into a register and processed at once? 32-bit word common, 64-bit faster double math 1 2 ... n-1 8 bits = 1 byte 16 bits 32 bits 64 bits It is not the size of the addressable element that depends on the size of the data bus, but, rather, the size of the word. The number of addressable elements depends on the size of the address bus. SPARC has a 32 bit word; a word is not always 32 bits. Mention the phrase “?-bit addressable”. SPARC’s memory is 8-bit addressable, i.e., byte addressable.
Single precision
Charles Babbage 1791-1871 Lucasian Professor of Mathematics, Cambridge University, 1827-1839 1/20/2009 CS152-Spring’09 CS252 S05
The first programmer Ada Byron aka “Lady Lovelace” 1815-52 Ada’s tutor was Babbage himself! 1/20/2009 CS152-Spring’09 CS252 S05
Babbage’s Influence Babbage’s ideas had great influence later primarily because of Luigi Menabrea, who published notes of Babbage’s lectures in Italy Lady Lovelace, who translated Menabrea’s notes in English and thoroughly expanded them. “... Analytic Engine weaves algebraic patterns....” In the early twentieth century - the focus shifted to analog computers but Harvard Mark I built in 1944 is very close in spirit to the Analytic Engine. 1/20/2009 CS152-Spring’09 CS252 S05
A Hierarchy of Languages Application Programs High-Level Languages Assembly Language Machine Language Hardware High-Level Language Low-Level Language Machine independent Machine specific
Bit depths in color 16 bits per pixel (high color) 5 bits for red, 5/6 bits for green, 5 bits for blue potential of 32 reds, 32/64 green, 32 blues total colors: 65536 32 bits per pixel (true color) 8 bits for red, green, blue, and alpha potential for 256 reds, greens, and blues total colors: 16777216 (more than the eye can distinguish)