Number Bases
ACS 2130 - Core Data Structures
Reminder: Self Paced Course Structure
Modules
Learning Outcomes
Number Bases: There are many ways to represent numbers
Back in the day: Unary Numbers
Basically there’s one symbol which represents 1 and it’s repeated
5: 11111
3:
15:
Eventually number systems evolved to use more than one symbol
Roman: I, II, III, IV, V, X, L, M etc.
Only gave unique symbols to 5, 10, 50, 100, 1000, etc.
Egyptian Numerals
You can even make your own!
Troll counting system from Terry Pratchett’s Discworld series
one, two, three, many, many-one, many-two, many-three, many many, many-many-one, many-many-two, many-many-three, many many many, many-many-many-one, many-many-many-two, many-many-three, LOTS.
Activity: 10 mins, make your own number system
Think about how would design your own number system
If you want to use emojis: ctrl + cmd + spacebar brings up the emoji palette
What if we gave each number their own symbol?
🤔
The Hindu-Arabic Numeral System
Use the position of the numeral as well
“We always add and never subtract. And each position is 10 more than the one before it.
So, 35 means “add 3*10 to 5*1″ and 456 means 4*100 + 5*10 + 6*1. This “positional decimal” setup is the Hindu-Arabic number system we use today.�
Source: https://betterexplained.com/articles/numbers-and-bases/
Base 10 (decimal)
Most modern day cultures use base-10, a.k.a. “decimal.”
We have 10 digits in base-10. (0 through 9)
9 rolls over to 10.
99 rolls over to 100.
Base 2 (binary)
Computers use base-2, a.k.a. “binary.”
There are 2 digits in base-2. (0 and 1) 1
1 rolls over to 10.
11 rolls over to 100.
“There are 10 kinds of people in the world. Those who understand binary, and those who don’t.”
–Old Programming Proverb
Counting in Binary
Binary to Decimal
Let’s Practice Binary to Decimal!
1 0 0 1 0
16 8 4 2 1
16 0 0 2 0
�
Flippy Do!
Decimal to Binary
Remainder Method, keep dividing by 2: https://owlcation.com/stem/How-to-Convert-Decimal-to-Binary-and-Binary-to-Decimal
Let’s Practice Decimal to Binary!
25 / 2 --->
Base 16
Computers sometimes also use base-16, a.k.a. “hexadecimal” or simply “hex.”
There are 16 digits in base-16. (0-9 and A-F)
9 continues to A. F rolls over to 10.
99 continues to 9A. FF rolls over to 100.
Base 16
Base 16
Hex is often prefixed with 0x
0xAF32010016 == AF32010016
Counting in Hex
Hex to Decimal
Check out this article: https://owlcation.com/stem/Convert-Hex-to-Decimal
Post more resources you find on piazza!
Let’s Practice Hex to Decimal!
0x D 3 F 2
(13 × 16³) + (3 × 16²) + (15 × 16¹) + (2 × 16⁰)
0
How would we go from Decimal to Hex?
Let’s Practice Decimal to Hex!
84 / 16 ---> 5 remainder of 4
5 / 16 r5
54
Hex to Binary
Let’s Practice Hex to Binary!
0x D 3 F 2
Think about this...
Based on what we’ve learned how would we convert from decimal to base 4?
Base 4 to decimal?
What about any arbitrary base n?