$\require{cancel}$

# Data and Memory

• As we discussed, the basic block of memory only holds a 0 or a 1.
• A system where we use two characters to represent things is called binary. (Especially 0 and 1)
• So how do we represent things in memory?
• How do we represent things in "real life?"
• We use 10 digits: 0, 1, 2, 3, 4, ..., 9
• We use 26 letters: a, b, c, d, ... z
• We use a shift to the letters to give us 26 more: A, B, C, ... Z
• We have some special "characters": ., +, ....
• Overall we have about 100 or so symbols we use to represent things.
• We are going to have to find a way to "encode" these in binary.
• Base 10
• The system we work in is called decimal or base 10.
• What does 739 really mean?
• $7\times10^2+3\times10^1+9\times10^0$.
• or
• 700
• +30
• + 9
• Remember, $10^0$ = 1
• The is a positional number system.
• The positions of the numbers indicate the power of 10 they are multiplied by.
• We have 10 different symbols, 0, 1, ... 9
• Once we pass these, we go to the next power of 10
• $9 + 1 = 10$
• $7 + 3 = 10$
• The number of symbols and the base are tied together.
• In binary we have two symbols.
• So we will use base 2.
• The numbers look strange as we only have 0 and 1.
• The positions represent different powers of 2.
• We will annotate base 2 numbers with the subscript 2.
• The simple ones are 0 and 1.
• $0_2 = 0$
• $1_2 = 1$
• The next two are
• $10_2 = 1\times2^1 + 0\times2^0 = 1 + 0 = 2$
• $11_2 = 1\times2^1 + 1\times2^0 = 1 + 1 = 3$
• There are 4 at the next level, can we find the decimal equivalent?
• $100_2$
• $101_2$
• $110_2$
• $111_2$
• There are 8 at the next level:
• $1000_2$
• $1001_2$
• $1010_2$
• $1011_2$
• $1100_2$
• $1101_2$
• $1110_2$
• $1111_2$
• This continues just like decimal.
• What is $1101101_2$ in decimal?
• You will work on this much more either in Logic and Switching Theory or in Computer Architecture.
• Given a n digit number in binary I expect you to be able to convert it to decimal.
• Binary numbers can get quite long, so we need another representation.
• The natural extension is to go to base 8 or base 16.
• Base 8 is called octal.
• Base 16 is called hexadecimal.
• For base 8 we need 8 symbols 0, 1, 2, ... 7
• For base 16 we need 16 symbols
• We have 10 : 0, 1, ... 9
• We just add: a, b, c, d, e, f
• $a_{16} = 10 = 1010_2$
• $b_{16} = 11 = 1011_1$
• $c_{16} = 12 = 1100_1$
• $d_{16} = 13 = 1101_1$
• $e_{16} = 14 = 1110_1$
• $f_{16} = 15 = 1111_1$
• So hex numbers will look something like
• $af305_{16}$
• $1032a_{16}$
• But subscripts are difficult to represent in some places so we use
• 0xaf305
• 0x1032a
• Conversion between binary and hex
• Binary to hex
• Group the number in blocks of four from the right.
• Pad on the left if necessary
• Convert to hex digits.
• Hex to binary
• Replace the hex number with the four equivalent binary digits.
• Decimal Binary HexDecimal BinaryHex
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 a
3 0011 3 11 1011 b
4 0100 4 12 1100 c
5 0101 5 13 1101 d
6 0110 6 14 1110 e
7 0111 7 15 1111 f
• Convert $1011010101110_2$ to hex
1011010101110

1 0110 1010 1110

0001 0110 1010 1110
1   6    a    e

0x16ae or $16a3_{16}$
• Convert $2af_{16}$ to binary
  2      a     f
0010   1010  1111

$10101111_2$
• Memory is a bunch of boxes.
• We distinguish between the boxes by giving each one an "address" or integer.
• The address is really just the distance from the start of memory.
• So the first memory address is 0, the next is 1
• But we tend to have a bunch of memory
• So addresses are given in hex.
• 0x00000000
• 0x00000001
• 0x0000000f
• 0x7affc30f
• 0xffffffff
• These systems are great for positive integers, but we also need to encode
• Negative integers
• Non-integer numbers (some of the rationals to be exact)
• Letter and other special symbols.
• We have different ways to represent each.
• Let's look at the characters.
• Characters are the symbols, digits and letters.
• We use a system called ascii
• The America Standard Code for Information Interchange.
• It use 8 bits or 2 hex digits.
• Look at the Ascii table on Wikipedia.
• Encode "Dan" in ascii.
• What is 48 65 6c 6c 6f 20 57 6f 72 6c 64 21? (all values are in hex)
• Given an ascii table, I would expect you to be able to encode and decode a message.
• There is a newer way to represent characters.
• unicode.
• But ascii is the first part.
• It is somewhat complex.
• But represents most known character sets.
• IE check out the Egyptian Hieroglyphs unicode page on wikipedia.
• We need a little binary, hex and ascii to get through this semester.