Bits, Datatypes,& Operationg ch2
Bits, Datatypes,& Operationg ch2
سازی
Numbers
Signed: -10, 5, 20, -123, …
Unsigned: 10, 120, 2…
Integers: 1, 2, 3, …
Floating point: 2x10-12, 6.23x104 , …
Complex: 2+j1 4.25+J6.23, …
Rational: 2.3456, 10.239, …
Text
Characters: a, b, c, …
Strings: “Tehran University”, “Bahman”, …
مبانی کامپیوتر و برنامه سازی 84 پاييز, 2
Data Types
Images:
Pixels:
Shapes:
Sound
Logical
True: “3>2”
False: “6-3=5”
Instructions
Add two numbers, multiply 3 by 2, …
مبانی کامپیوتر و برنامه سازی 84 پاييز, 3
Decimal Numbers
Binary to Decimal
Binary an….a2a1a0 = Decimal an*2n+ …. +a2*22 +a1*21+a0*20
Example:
10111
+ 111
Advantages: -2 11110
• Only one representation for zero -1 11111
• Operations need not check the sign 0 00000
• Efficient use of all the bits +1 00001
+2 00010
+3 00011
… …
+15 01111
مبانی کامپیوتر و برنامه سازی 84 پاييز, 21
Two’s complement addition
Addition
All numbers should have the same number of
bits
Ignore carry out
Unsigned representation
0 ≤ i < 2N - 1
Signed Magnitude
-2N-1 + 1 < i < 2N-1 - 1
1’s Complement
-2N-1 + 1 < i < 2N-1 - 1
2’s Complement
-2N-1 < i < 2N-1 - 1
0.329
In Decimal: 10-1 10-2 10-3
3x0.1 + 2x0.01 + 9x0.001 = 329
0.011
In Binary 2-1 2-2 2-3
0x0.5 + 1x0.25 + 1x0.125 = 0.375
10111111010000000000000000000000
1 11 bits 52 bits
s exponent fraction
011101010001111010011010111
3 A 8 F 4 D 7
16AB16 = x16AB
= 1x163 + 6x16 2 + 10x16 + 11
= 580310 = #5803
= 0001 0110 1010 10112
Sound
sequence of fixed-point numbers
مبانی کامپیوتر و برنامه سازی 84 پاييز, 44