pptx - code school

advertisement
http://proglit.com/
numbers
SA
BY
bit
(one of two states)
number system
(a scheme for symbolically and verbally
representing quantity)
unary
(the tally system)
Aiwt$e#
&!)9?
positional notation
(represents arbitrarily large quantities
using a finite set of symbols)
decimal
base-10
(positional notation using 10 symbols)
Arabic numerals
0 1 2 3 4 5 6 7 8 9
39
40
9
09
…0000000009
09
10
86999
87000
78
seventy-eight
seven eight
octal
base-8
(positional notation using 8 symbols)
0 1 2 3 4 5 6 7
07
10
octal
base-8
1
2
3
4
5
6
7
10
11
12
13
14
decimal
base-10
1
2
3
4
5
6
7
8
9
10
11
12
octal
base-8
15
16
17
20
21
22
23
24
25
26
27
30
decimal
base-10
13
14
15
16
17
18
19
20
21
22
23
24
317777
320000
61 (decimal)
061 (octal)
05673
hexadecimal
hex
base-16
(positional notation using 16 symbols)
0 1 2 3 4 5 6 7
8 9 A B C D E F
0F
10
hex
base-16
1
2
3
4
5
6
7
8
9
A
B
C
decimal
base-10
1
2
3
4
5
6
7
8
9
10
11
12
hex
base-16
D
E
F
10
11
12
13
14
15
16
17
18
decimal
base-10
13
14
15
16
17
18
19
20
21
22
23
24
hex
base-16
19
1A
1B
1C
1D
1E
1F
20
21
22
23
24
decimal
base-10
25
26
27
28
29
30
31
32
33
34
35
36
ADD
BAD
BEAD
BEE
BEEF
CAFE
DEAD
DEAF
DEED
FAD
FEED
0xADD
0xBAD
0xBEAD
0xBEE
0xBEEF
0xCAFE
0xDEAD
0xDEAF
0xDEED
0xFAD
0xFEED
0xA3BFFFFF
0xA3C00000
binary
base-2
(positional notation using 2 symbols)
0 1
01
10
binary
base-2
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
decimal
base-10
1
2
3
4
5
6
7
8
9
10
11
12
binary
base-2
1101
1110
1111
10000
10001
10010
10011
10100
10101
10110
10111
11000
decimal
base-10
13
14
15
16
17
18
19
20
21
22
23
24
101b (binary)
101 (decimal)
10101111b
10110000b
http://proglit.com/
base conversions
36259
(30000)
+ (6000)
+ (200)
+ (50)
+ (9)
(3 * 10000)
+ (6 * 1000)
+ (2 * 100)
+ (5 * 10)
+ (9 * 1)
+
+
+
+
(3
(6
(2
(5
(9
*
*
*
*
*
4
10 )
3
10 )
2
10 )
1
10 )
0
10 )
36259
104
103
102
101
10000
1000
100
10
100
1
octal to decimal
03675
(03000)
+ (0600)
+ (070)
+ (05)
(03 * 01000)
+ (06 * 0100)
+ (07 * 010)
+ (05 * 01)
(03
+ (06
+ (07
+ (05
3
010 )
*
2
* 010 )
1
* 010 )
0
* 010 )
(3
+ (6
+ (7
+ (5
3
8)
*
2
* 8 )
1
* 8 )
0
* 8 )
(3 * 512)
+ (6 * 64)
+ (7 * 8)
+ (5 * 1)
(1636)
+ (384)
+ (56)
+ (5)
03675
=
2081
decimal to octal
36256
+
+
+
+
(3
(6
(2
(5
(6
*
*
*
*
*
4
10 )
3
10 )
2
10 )
1
10 )
0
10 )
+
+
+
+
(03
(06
(02
(05
(06
*
*
*
*
*
4
012 )
3
012 )
2
012 )
1
012 )
0
012 )
(03 * 023420)
+ (06 * 01750)
+ (02 * 0144)
+ (05 * 012)
+ (06 * 01)
(072460)
+ (013560)
+ (0310)
+ (062)
+ (06)
36256
=
0106640
hex to decimal
0x36E59
+
+
+
+
(0x3
(0x6
(0xE
(0x5
(0x9
*
*
*
*
*
4
16 )
3
16 )
2
16 )
1
16 )
0
16 )
(3 * 65536)
+ (6 * 4096)
+ (14 * 256)
+ (5 * 16)
+ (9 * 1)
(196608)
+ (24576)
+ (3584)
+ (80)
+ (9)
0x36E59
=
224857
binary to decimal
10101b
+
+
+
+
(1
(0
(1
(0
(1
*
*
*
*
*
4
2)
3
2 )
2
2 )
1
2 )
0
2 )
(1 * 16)
+ (0 * 8)
+ (1 * 4)
+ (0 * 2)
+ (1 * 1)
(16)
+ (0)
+ (4)
+ (0)
+ (1)
10101b
=
21
10101101b
10101101b
128
32
8
4
1
(128)
+ (32)
+ (8)
+ (4)
+ (1)
10101101b
=
173
22
23
24
25
26
27
28
29
210
211
212
213
214
215
216
217
218
219
220
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
decimal to binary
1) find biggest fitting power
of two
2) subtract it out
3) repeat until left with 0
35872
35872
15
32768 (2 )
1???????????????b
35872 - 32768
=
3104
3104
11
2048 (2 )
10001???????????b
3104 – 2048
=
1056
1056
10
1024 (2 )
100011??????????b
1056 – 1024
=
32
32
5
32 (2 )
10001100001?????b
32 – 32
=
0
1000110000100000b
why use hex and octal?
octal to binary
(and vice versa)
octal
base-8
0
1
2
3
4
5
6
7
binary
base-2
000
001
010
011
100
101
110
111
03673
octal
base-8
0
1
2
3
4
5
6
7
binary
base-2
000
001
010
011
100
101
110
111
03673
011110111011b
1101010110b
001101010110b
01526
hex to binary
(and vice versa)
hex
base-16
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
binary
base-2
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0x7E9
011111101001b
1100101101b
0x32D
recap
Each digit is a coefficient of the number base raised to an increasing power.
One technique works for all number base conversions.
Shortcut conversions:
• decimal to binary (sum powers of 2)
• binary to decimal (subtract out powers of 2)
• octal and binary (1 octal digit = 3 binary digits)
• hex and binary (1 hex digit = 4 binary digits)
Effectively, hex and octal serve as a compacter way of writing binary.
http://proglit.com/
meaning relies
upon agreement
integer
(whole number)
5878
0
-87
234
signed integer
unsigned integer
0, 1, 2,
3,
4,
5…
0b, 1b, 10b, 11b, 100b, 101b…
n bits =
n
2
values
1 bit = 2 values
2 bits = 4 values
3 bits = 8 values
4 bits = 16 values
5 bits = 32 values
6 bits = 64 values
7 bits = 128 values
8 bits = 256 values
etc…
unsigned value range
1 bit = 0..1
2 bits = 0..3
3 bits = 0..7
4 bits = 0..15
5 bits = 0..31
6 bits = 0..63
7 bits = 0..127
8 bits = 0..255
etc…
sign bit
00000011
(positive three)
10000011
(negative three)
one’s complement
00000011
(positive three)
11111100
(negative three)
two’s complement
00000011
(positive three)
11111101
(negative three)
two’s complement
11111101
(negative three)
00000011
(positive three)
excess-n
00001011
(positive three in excess-8)
00000101
(negative three in excess-8)
excess-n
00101101
(positive three in excess-42)
00100111
(negative three in excess-42)
8-bit range
sign bit: -127 to +127
one’s complement: -127 to +127
two’s complement: -128 to +127
rational numbers
2/5
1/98
7/1
-61/1738
radix-point notation
(ratio written as an integer component and a
fractional component, separated by a radix point)
3/4
1/8
-7/1
138/20
0.75
0.125
-7.0
6.9
36.259
(30)
+ (6)
+ (0.2)
+ (0.05)
+ (0.009)
1
10 )
(3 *
0
+ (6 * 10 )
-1
+ (2 * 10 )
-2
+ (5 * 10 )
-3
+ (9 * 10 )
36.259
101
100
10-1
10
1
1/10
10-2
10-3
1/100 1/1000
062.732
81
8
80
1
8-1
1/8
8-2
1/64
8-3
1/512
10.111b
21
20
2-1
2-2
2-3
2
1
1/2
1/4
1/8
finite rational
(rational with a fractional component which can be
expressed with a finite number of digits)
3/4
-7/1
138/20
1/3
738/61
0.75
-7.0
6.9
0.33
12.0983606557…
a ratio with denominator 2a5b is finite in decimal
a ratio with denominator 2a is finite in octal
a ratio with denominator 2a is finite in hex
a ratio with denominator 2a is finite in binary
all ratios which are finite in binary are also finite in decimal
some ratios which are finite in decimal are also finite in binary
rational as two integers
3/4
Numerator: 00000011
Denominator: 00000100
-7/13
Numerator: 11111001
Denominator: 00001101
fixed-point
(the computing equivalent
of radix-point notation)
57/8
111.001b
Integer: 00000111
Fraction: 00100000
scientific notation
engineering notation
362.354 = 3.62354 * 102
0.00736234 = 7.36234 * 10-3
989777.1 = 9.897771 * 105
floating-point
(the computing equivalent
of scientific notation)
21/2
1010.1b
1.0101b * 23
Significand: 10101000
Exponent: 00000011
6.75
6.75
110b + 0.?b
0.75
3/4
3/4
1/2 + 1/4
-1
-2
2 + 2
6.75
=
110.11b
110.11b
=
2
1.1011b * 2
1.1011b *
2
2
Significand: 11011000
Exponent: 00000010
IEEE floating-point
(an international standard)
http://proglit.com/
Download