CS 104 Introduction to Computer Science and Graphics Problems

advertisement
CS 104 Introduction to
Computer Science and
Graphics Problems
Data Representation(1)
Number Systems
09/12 ~ 09/16 /2008
Yang Song
(Prepared by Yang Song and Suresh Solaimuthu)
Did you see this T-shirt before?
There are 10 types of people;
those who understand binary
and those who don't.
What is Data?

In computer science, data is any information
in a form suitable for use with a computer.

In an alternate usage, binary files (which are
not human-readable) are sometimes called
“data”, as distinguished from human-readable
“text”.
Numerals and Number Systems




Arabic Numerals: 1, 2, 3, ….
Roman Numerals: I, II, III, ….
Others? 一, 二, 三, ….
Decimal System




Uses ten digits 0 ~ 9
Base 10
4321 =? 4x103 + 3x102 + 2x101 + 1x100
Binary System


Uses 2 digits 0, 1
Base 2
Some Units for Computer

Bit: single Binary Digit
- 1, 0.

Nibble (Nybble): 4-bit aggregation
- 1010

Byte (Octet): 8-bit aggregation
- 1101 0010

Bigger ones?
-
-
KiloByte (KB): 210 (1,024) bytes
MegaByte (MB): 220 (1,048,576) bytes
GigaByte (GB): 230 (1,073,741,824) bytes
Decimal and Binary

Computer “reads” binary

Simple

Only two symbols

How can we convert them?
Binary  Decimal

The value of each position
For Base 10, it is 100, 101, 102, 103 … etc.
For Base 2, so, 20, 21, 22, 23 … etc.


Convert binary 10112 into decimal:
Position Value
8
4
2
1
Binary
1
0
1
1
Actual
8x1 4x0 2x1 1x1
So it is: 8 + 2 + 1 = 11
Decimal  Binary


Division: Decimal number is the dividend,
divisor is the “base”, so it’s 2 now, quotient
becomes new dividend and save the
remainder…until quotient < base, trace back
from the last quotient to ALL the remainders.
Decimal 11: so, it’s 10112
Dividend
11
5
2
Quotient
5
2
1
Remainder
1
1
0
Another example

Convert 40 (decimal) into binary number:
Dividend
40
20
10
5
2
Quotient
20
10
5
2
1
0
0
1
0
Remainder 0


So it is: 1010002
Can you convert decimal into base-7 number?
Octal Number



Octal has 8 symbols: 0, 1, 2, 3….7
Base 8
Convert 14708 into decimal:



Convert back?
Dividend
824
103
12
Quotient
103
12
1
Remainder
0
7
4
Convert 11010102 into octal:



1x83 + 4x82 + 7x81 + 0x80 = 82410
Group them into 3 bits (why?)
1 101 010  1 5 2 8
Can you confirm this?
Hexadecimal Number

Hexadecimal uses sixteen symbols:




Base 16
Range of a Byte: 00 ~ FF, why?
Convert A2C into decimal



10x162 + 2x161 + 12x160 = 260410
Convert 260410 into Hexadecimal number?
Dividend
2604
162
Quotient
162
A(10)
Remainder
C(12)
2
Convert 101000111112 into hexadecimal



0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Group into 4 bits (why?)
101 0001 1111  51F16
Confirm this one?
Download