Transcript File
Binary Representation
in Text
Why is it important to know how to convert
between Hex, Dec, Binary?
• Binary and hexadecimal are useful because it turned out that it was more
practical to construct complex machinery that uses digital electronics rather
than analog electronics.
• Octal numbering is also used, but it is not as useful for our purpose as Binary,
Hexadecimal and Decimal systems.
• In the context of electronics, it means a current or voltage is used to turn
on, or turn off a “switch.”
• Thus it is practical for the on/off values to be just two -- on or off. Thus the
easiest way for our electronics to work in terms of “bits”, or binary digits.
Why is it important to know how to convert
between Hex, Dec, Binary?
• The other numbering systems (hexadecimal
and octal) became useful as a result.
• Binary numbers are a pain for humans to deal
with because they get large, in terms of
number of digits quickly. Example,
111000110011100100110010000000111010001
111110010
• …and humans don’t like numbers with lots of
digits.
Why is it important to know how to
convert between Hex, Dec, Binary?
• To make things easier for ourselves, it
makes sense to group raw binary code and
treat these groups as a single digit. Each
digit in the hexadecimal system is
equivalent to a four-digit binary numbers.
• Example: f (in hexadecimal) = 1111 (binary
code)
ASCII
• ASCII is an acronym for the American Standard Code for
Information Interchange.
• It is a standard seven-bit code that was first proposed by
the American National Standards Institute or ANSI in
1963, and finalized in 1968 as ANSI Standard X3.4.
• The purpose of ASCII was to provide a standard to code
various symbols both visible (letters, numbers,
punctuation) and invisible symbols (space bar, enter tab,
shift, control etc…).
ASCII
• In the ASCII character set, each binary value between 0 and 127
represents a specific character.
• Most computers extend the ASCII character set to use the full
range of 256 characters available in a byte. The upper 128
characters handle special things like accented characters from
common foreign languages.
ASCII
• In general, ASCII works by assigning standard numeric values
(decimal) to letters, numbers, punctuation marks and other
characters such as control codes.
• An uppercase "A," for example, is represented by the decimal
number 65."
Bytes and ASCII
• By looking at the ASCII table, you can clearly see a oneto-one correspondence between each character and the
ASCII code used.
• For example, 32 is the ASCII code for a space.
• We could expand these decimal numbers out to binary
numbers where 32 = 00100000, if we wanted to be
technically correct -- that is how the computer really
deals with things.
Bytes and ASCII
• Computers store text documents, both on disk and
in memory, using these ASCII codes.
• For example, if you use Microsoft Word in Windows
XP/2000 to create a text file containing the words,
“Friends, Romans, Countrymen” Word would use 1
byte (8 bits) of memory per character (including 1
byte for each space character between the words)
• In this example, the total would be - 27 characters.
• When Word stores the sentence in a file on disk, the
file will also contain 1 byte per character and per
space.
Bytes and ASCII
• If you were to look at the file as a computer looks at it, you would find that
each byte contains not a letter but a number -- the number is the ASCII code
(decimal) corresponding to the character. So on disk, the numbers for the
file look like this:
• Text - Friends, Roman, Countrymen
• Decimal Format - 70 114 105 101 110 100 115 44 32 82 111 109 97 110 115 44
32 67 111 117 110 116 114 121 109 101 110
• Binary Format - 01000110 01110010 01101001 01100101 01101110 01100100
01110011 00101100 00100000 01010010 01101111 01101101 01100001
01101110 00101100 00100000 01000011 01101111 01110101 01101110
01110100 01110010 01111001 01101101 01100101 01101110
Bytes and ASCII
• Externally, it appears that human beings will use natural
languages symbols to communicate with computer – English,
French, Arabic, Spanish and etc…
• But a computer will convert the decimal, or hexadecimal, code
into binary data and then process all information in binary
world.
• Finally, computer will convert binary information back to
decimal, or hexadecimal, code which is then converted into
symbols and characters understandable to human beings.
Bytes and ASCII
• When you type the letter A, the hardware logic built into the keyboard
automatically translates that character into the ASCII code 65 (decimal
value).
• This is then sent to the computer and read in binary (0100 0001).
• Similarly, the computer takes the binary code and sends the ASCII code
65 (decimal value) to output devices, the output hardware interprets
the code and draws the letter “A” on your screen of your computer.
• As such, this is how binary code is used to create text on a computer.
• Input - A 65 0100 0001
• Output - 0100 0001 65 A
Layered View of Representation
Input sequence below
Text
string
Sequence of
characters
Information
Output sequence below
Information
Character
Data
Information
Data
Information
Bit string
Data
Data
A great
diagram
to copy.
Unicode - representation
• ASCII code can represent 8 bits information only 128 = 27 characters.
• It only represents the English Alphabet plus some control characters.
• Unicode is designed to represent the worldwide interchange by
recognizing more than one language.
• It uses 16 bits and can represents 32,768 = 215 characters.
ASCII Assignment
• Using ASCII you are to write the following messages:
1. Your name – convert it to decimal than to binary. Have your
partner convert it back to text.
2. Write a sentence for a friend, put it into decimal and then have
your partner decode it in class.