.ppt compilation

advertisement
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
0
1
2
3
4
5
6
7
8
Binary (LR)
0000
0001
0010
0011
0100
0101
0100
0111
1000
Binary (R L)
0000
1000
0100
1100
etc.
Is “most significant bit” (MSB) at “right” or “left”?
(right and left are arbitraryin computer chip memory space)
Powers of 2
20
21
22
23
24
25
26
27
Decimal
1
2
4
8
16
32
64
128
28
29
210
211
212
213
214
215
Decimal
256
512
1024
2048
4096
8192
16384
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
0
1
2
3
4
5
6
7
Binary
0000
0001
0010
0011
0100
0101
0110
0111
Hex
8
9
Binary
1000
1001
A
1010
B
1011
C
1100
D
1101
E
1110
F
1111
Characters and strings
• 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.”
CSE360
8
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
*
1
2
A
B
a
b
}
Decimal Value
42
49
50
65
66
97
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.
8 bits = 1 byte
16 bits
32 bits
64 bits
0
0
0
0
1
1
1
1
2
2
2
2
...
...
...
...
n-1
n-1
n-1
n-1
– 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
Single precision
Charles Babbage 1791-1871
Lucasian Professor of Mathematics,
Cambridge University, 1827-1839
1/20/2009
CS152-Spring’09
13
The first programmer
Ada Byron aka “Lady Lovelace” 1815-52
Ada’s tutor was Babbage himself!
1/20/2009
CS152-Spring’09
14
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
15
A Hierarchy of Languages
Application Programs
High-Level Languages
Machine independent
High-Level Language
Machine specific
Low-Level Language
Assembly Language
Machine Language
Hardware
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)
Download