Title: IT-101 Section 001
1IT-101Section 001
Introduction to Information Technology
2- Chapter 3
- Representing Information in Binary Form (cont..)
- Binary to decimal conversion
- Decimal to binary conversion
3Representing Information in Binary Form
- BInary digiTal symbols (BITs) form a universal
language for any - Numbers
- Text
- Sound
- Images
- Video
- Anything else you can imagine
- How is this possible????
011010100101
How can numbers and text be represented in binary
code????
Today's Topic
4How Do We Normally Represent Numbers?
Before we discuss binary code, lets think about
the number system we use every day.
The Decimal System
- We normally dont use Binary Digits (Bits) (in
which a single placeholder can hold only 0 or 1)
in everyday life. - We use Decimal Digits - a single placeholder can
hold one of ten numerical values between 0 and 9.
- Digits are combined together into larger numbers.
- For example 8,234 is made up of 4 digits. The 4
holds the 1s place, the 3 holds the 10s
place, the 2 holds the 100s place and the 8
holds the 1000s place.
5The Decimal System
- Decimal digits are combined to create larger
numbers4,567 gt (4 x 103) (5 x 102) (6 x
101) (7 x 100) - 10 raised to the power of
- 100 1
- 101 10
- 102 10x10100
- 103 10x10x101,000
- 104 10x10x10x1010,000
- and so on
- Also called Base-10 system
- There are other ways of representing numbers
other than using the digits 0, 1, 2, 3, 4, 5, 6,
7, 8, and 9.
We have ten fingers and use ten digits!
Coincidence?
6Comparing the Decimal Number System to the Binary
Number System
- While people routinely use decimal digits,
computers use binary digits. - The decimal system uses ten numbers (0, 1, 2, 3,
4, 5, 6, 7, 8, 9) to represent all values. The
binary system uses two numbers (0 and 1) to
represent all values. - In other words, computers use the base-2 system
rather than the base-10 system. - Counting in binary is simple (different, but
simple) because you use powers of two instead of
ten. Example follows.
7Binary to Decimal Conversion
The same as calculating the value of a decimal
system number except use powers of two instead of
powers of ten.
- The binary number 1101 can be converted to
decimal as follows (1x23) (1x22)
(0x21) (1x20) 8 4 0 1 13 - For understanding binary, its helpful to have a
good command of powers of 2
20 1 21 2 22 2x2 4 23 2x2x2 8 24
2x2x2x2 16 25 2x2x2x2x2 32
26 2x2x2x2x2x2 64 27 2x2x2x2x2x2x2 128 28
2x2x2x2x2x2x2x2 256 29 2x2x2x2x2x2x2x2x2
512 210 2x2x2x2x2x2x2x2x2x2 1024 and so on...
8Binary versus Decimal Numbers
Another Way to Think About It.
Decimal Number
Binary Number
10,000s place
1,000s place
100s place
10s place
16s place
2s place
1s place
4s place
8s place
1s place
1 0 1 0 1
9 5, 1 0 7
9 x 10,000 90,000 5 x 1,000 5,000 1 x 100
100 0 x 10 0 7 x 1 7 _______________
95,107 (10)
1 x 16 16 0 x 8 0 1 x 4 4 0 x 2 0
1 x 1 1 _______________ 21 (10)
9Another Example Converting Binary to Decimal
- A computer generates the following sequence of
bits 110101(2) - How do we convert 110101(2) into decimal?
(1x25) (1x24) (0x23) (1x22) (0x21)
(1x20) 32 16 0
4 0 1 53(10)
110101(2) 53(10)
10Real World Example The Internet Address
Converting a 32-bit Internet address into dotted
decimal format
- An Internet address, known as an IP address for
Internet Protocol is comprised of four binary
octets, making it a 32-bit address. - IP addresses, difficult for humans to read in
binary format, are often converted to dotted
decimal format. - To convert the 32-bit binary address to dotted
decimal format, divide the address into four
8-bit octets and then convert each octet to a
decimal number. - Each octet will have one of 256 values (0 through
255)
192.48.29.253 (IP address in dotted decimal form)
11Real World Example The Internet Address
Convert the following 32-bit Internet address
into dotted decimal format 010111100001010011000
01111011100
1) Divide the IP address into four
octets 01011110 00010100 11000011
11011100 2) Convert each binary octet into a
decimal number 01011110 6416842
94 00010100 164 20 11000011 1286421
195 11011100 128641684 220 3) Write out
the decimal values separated by
periods 94.20.195.220
12Decimal to Binary Conversion
- Sometimes it can be done intuitively.
- For example
- The decimal number 1 represented in 8-bit binary
is - 00000001.
- The decimal number 128 represented in 8-bit
binary is - 10000000.
- The decimal number 129 represented in 8-bit
binary is - 10000001.
- The decimal number 2 represented in 8-bit binary
is - 00000010.
- The decimal number 4 represented in 8-bit binary
is - 00000100.
- The decimal number 6 represented in 8-bit binary
is - 00000110.
But what are we really doing mathematically?
13- Convert the Decimal Number 174 to a binary octet
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 1 Compare 174 to 128. 174gt128 so place a 1
in the 128s place and subtract 174-128 46
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 2 Compare 46 to 64. 46lt64 so place a 0 in
the 64s place and continue with 46.
1
0
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
14Reversing the Process Converting a Decimal
Number to Binary
1
0
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 3 Compare 46 to 32. 46gt32 so place a 1 in
the 32s place and subtract 46-32 14
1
0
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 4 Compare 14 to 16. 14lt16 so place a 0 in
the 16s place and continue with 14.
0
1
0
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 5 Compare 14 to 8. 14gt8 so place a 1 in
the 8s place and subtract 14-86.
150
1
0
1
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 6 Compare 6 to 4. 6gt4 so place a 1 in the
4s place and subtract 6-42.
0
1
0
1
1
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
Step 7 Compare 2 to 2. 22 so place a 1 in the
2s place and subtract 2-20. There is no
remainder left to convert, so also place a 0 in
the 1s place.
0
1
0
1
1
1
0
1
____ ____ ____ ____ ____ ____
____ ____
1s place
2s place
4s place
8s place
16s place
32s place
64s place
128s place
The decimal number 174 has been converted to the
binary number 10101110
16Another Approach Converting from Decimal to
Binary Using BCD
- We can also simply represent one number at a
time. - How can we represent the ten decimal numbers
(0-9) in binary code?
Numeral 0 1 2 3 4 5 6 7 8 9
BCD Representation 0000 0001 0010 0011 0100 0101 0
110 0111 1000 1001
Binary Coded Decimal
- We can represent any integer by a string of
binary digits. - For example, 749 can be represented in binary as
011101001001
17Binary Conventions
- Most Significant Bit (MSB) and Least Significant
Bit (LSB) - Decimal Example 64
- 6 is the Most Significant Digit
- 4 is the Least Significant Digit
- Binary 1000000
- 1 is the MSB
- 0 on the right is the LSB
- Subscripts Note that the subscript 2 makes it
clear a number is in binary format and the
subscript 10 makes it clear a number is in
decimal format. - This avoids confusion between a number like
110101 which can either be binary, written as
110101(2) or decimal, written as 110,101(10)
18- If there is a 1 in the LSB of a binary number,
then its decimal equivalent is an odd number - If there is a 0 in the LSB of a binary number,
then its decimal equivalent is an even number
19In-Class Examples
- Convert 12(10) to binary representation
- Convert 1010101(2) to decimal
- Convert 6234(10) to binary coded decimal (BCD)
representation - Convert 256(10) to binary representation
- Convert 10001110(2) to decimal
20How Many Bits Are Necessary to Represent
Something?
- 1 bit can represent two (21) symbols
- either a 0 or a 1
- 2 bits can represent four (22) symbols
- 00 or 01 or 10 or 11
- 3 bits can represent eight (23) symbols
- 000 or 001 or 011 or 111 or 100 or 110 or 101 or
010 - 4 bits can represent sixteen (24) symbols
- 5 bits can represent 32 (25) symbols
- 6 bits can represent 64 (26) symbols
- 7 bits can represent 128 (27) symbols
- 8 bits (a byte) can represent 256 (28) symbols
- n bits can represent (2n) symbols!
- Sohow many bits are necessary for all of us in
class to have a unique binary ID? Are two bits
enough? Three? Four? Five? Six? Seven?
21To think about..
- Can 64 bits represent twice as many symbols as 32
bits? - 32 bit 232 4,294,967,296 symbols
- 64 bit 264 1.8 x 1019 symbols
- 128 bit 2128 3.4 x 1038 symbols
- Can 8 bits represent twice as many symbols as 4
bits? - 8 bit 28 256 symbols
- 4 bit 24 16 symbols
- Remember that were dealing with exponents!
- 8 bit is twice as big as __________?
- 7 bit!
- 7 bits can represent 27 possible symbols or
2x2x2x2x2x2x2 128 - 8 bits can represent 28 possible symbols or
2x2x2x2x2x2x2x2 256
22Exercises
- Convert the following to binary form
- 810
- 4010
- 10110
- Convert the following to decimal form
- 11002
- 001100102
- 011112
23Comments for next class
- Do the assigned exercises
- Topics to be covered next class
- Bits vs. Bytes
- Representing real numbers in binary form
- Representing negative numbers in binary form
- Octal numbering system
- Hexadecimal numbering system
- Conversion between different numbering systems
- Representing alphanumeric characters in binary
form