UMBC CMSC 104 – Section 01, Fall
UMBC CMSC 104, Section 01 - Fall 2016 Nothing. Enjoy your weekend! 2
UMBC CMSC 104, Section 01 - Fall 2016 I want to try something different with this class… Everyone log off your PC and put away your phones/calculators/electronic devices! Break out some paper and a pen/pencil We will be done the slides quickly. I will put up some conversion “problems” at the end to test your understanding. We’re all adults here – if you need more help, you can stay. If it “clicks”, you can go. Don’t be concerned if it doesn’t “click” right away. Stick around. 3
UMBC CMSC 104, Section 01 - Fall A bit is a single binary digit (a 1 or 0). A byte is 8 bits A word is 32 bits or 4 bytes Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits Programming languages use these standard number of bits when organizing data storage and access.
UMBC CMSC 104, Section 01 - Fall The on and off states of the capacitors in RAM can be thought of as the values 1 and 0, respectively. Therefore, thinking about how information is stored in RAM requires knowledge of the binary (base 2) number system. Let’s review the decimal (base 10) number system first.
UMBC CMSC 104, Section 01 - Fall The decimal number system is a positional number system. Example: X = X 10 0 = 1 2 X 10 1 = 20 6 X 10 2 = X 10 3 = 5000
UMBC CMSC 104, Section 01 - Fall 2016 The decimal number system is also known as base 10. The values of the positions are calculated by taking 10 to some power. Why is the base 10 for decimal numbers? Because we use 10 digits, the digits 0 through 9. 7
UMBC CMSC 104, Section 01 - Fall 2016 The binary number system is also known as base 2. The values of the positions are calculated by taking 2 to some power. Why is the base 2 for binary numbers? Because we use 2 digits, the digits 0 and 1. 8
UMBC CMSC 104, Section 01 - Fall The binary number system is also a positional numbering system. Instead of using ten digits, 0 - 9, the binary system uses only two digits, 0 and 1. Example of a binary number and the values of the positions: ?
UMBC CMSC 104, Section 01 - Fall X 2 0 = X 2 1 = 0 1 X 2 2 = = = 16 1 X 2 3 = = = 32 0 X 2 4 = = = 64 0 X 2 5 = = 81 X 2 6 =
UMBC CMSC 104, Section 01 - Fall Practice conversions: Binary Decimal ?
UMBC CMSC 104, Section 01 - Fall Make a list of the binary place values up to the number being converted. Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left. Continue until the quotient is zero. Example:
UMBC CMSC 104, Section 01 - Fall Practice conversions: Decimal Binary
UMBC CMSC 104, Section 01 - Fall = ? Humans can’t work well with binary numbers; there are too many digits to deal with. Memory addresses and other data can be quite large. Therefore, we sometimes use the hexadecimal number system.
UMBC CMSC 104, Section 01 - Fall The hexadecimal number system is also known as base 16. The values of the positions are calculated by taking 16 to some power. Why is the base 16 for hexadecimal numbers ? Because we use 16 symbols, the digits 0 through 9 and the letters A through F.
UMBC CMSC 104, Section 01 - Fall BinaryDecimalHexadecimal A B C D E F
UMBC CMSC 104, Section 01 - Fall Example of a hexadecimal number and the values of the positions: 3 C 8 B
UMBC CMSC 104, Section 01 - Fall Binary: Decimal: Hexadecimal: 50A7 16 Notice how the number of digits gets smaller as the base increases.
UMBC CMSC 104, Section 01 - Fall 2016 Because both Hex and Binary are based on powers of two, converting from Binary to Hex (or Hex to Binary) is simple. Binary: Hex F 4 B D 16 19
UMBC CMSC 104, Section 01 - Fall 2016 Same principals as before… Try converting this hexadecimal value to decimal 3 A F 9. B 16 B X = X 16 0 = 9 F X 16 1 = 240 A X 16 2 = X 16 3 =
UMBC CMSC 104, Section 01 - Fall Make a list of the hex place values up to the number being converted. Perform successive divisions by 16, placing the remainder in each of the positions from right to left. Continue until the quotient is zero. Example: B
UMBC CMSC 104, Section 01 - Fall 2016 The logic we’ve applied goes for any arbitrary number system What would a base 7 number system look like? X 7 -1 = X 7 0 = 1 2 X 7 1 = 14 6 X 7 2 = X 7 3 =
UMBC CMSC 104, Section 01 - Fall
UMBC CMSC 104, Section 01 - Fall 2016 From Decimal to Binary 19 89 234 From Binary to Decimal
UMBC CMSC 104, Section 01 - Fall 2016 From Decimal to Binary 19 = 89 = 234 = From Binary to Decimal = 29 = 150 =
UMBC CMSC 104, Section 01 - Fall 2016 From Decimal to Hex 116 516 From Hex to Decimal A7 B0B 26
UMBC CMSC 104, Section 01 - Fall 2016 From Decimal to Hex 116 = 74 516 = 204 From Hex to Decimal A7 = 167 B0B =
28
UMBC CMSC 104, Section 01 - Fall
UMBC CMSC 104, Section 01 - Fall