1 of 30

Number Bases

ACS 2130 - Core Data Structures

2 of 30

Reminder: Self Paced Course Structure

  • 1 hour: lecture/activities
  • 15 min: Break
  • 1.5 hours: Required Lab Time (working on modules)

Modules

  • Self assessments
  • Mastery portion required
  • Stretch are for your own learning if you choose to complete them
  • Videos, links, reading, exercises

3 of 30

Learning Outcomes

  • Be able to explain the concept of representing numbers in different formats
  • Be able to understand the differences between base 10, base 2, and base 16 number systems
  • Be able to explain how to convert between various number bases at a high level

4 of 30

Number Bases: There are many ways to represent numbers

5 of 30

Back in the day: Unary Numbers

Basically there’s one symbol which represents 1 and it’s repeated

5: 11111

3:

15:

6 of 30

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

7 of 30

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.

8 of 30

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

9 of 30

What if we gave each number their own symbol?

🤔

10 of 30

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/

11 of 30

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.

https://www.youtube.com/watch?v=DKavhec9fGE

12 of 30

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.

13 of 30

“There are 10 kinds of people in the world. Those who understand binary, and those who don’t.”

–Old Programming Proverb

14 of 30

Counting in Binary

15 of 30

Binary to Decimal

16 of 30

Let’s Practice Binary to Decimal!

1 0 0 1 0

16 8 4 2 1

16 0 0 2 0

17 of 30

Flippy Do!

18 of 30

Decimal to Binary

19 of 30

Let’s Practice Decimal to Binary!

25 / 2 --->

20 of 30

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.

21 of 30

Base 16

22 of 30

Base 16

Hex is often prefixed with 0x

0xAF32010016 == AF32010016

23 of 30

Counting in Hex

24 of 30

Hex to Decimal

Check out this article: https://owlcation.com/stem/Convert-Hex-to-Decimal

Post more resources you find on piazza!

25 of 30

Let’s Practice Hex to Decimal!

0x D 3 F 2

(13 × 16³) + (3 × 16²) + (15 × 16¹) + (2 × 16⁰)

0

26 of 30

How would we go from Decimal to Hex?

27 of 30

Let’s Practice Decimal to Hex!

84 / 16 ---> 5 remainder of 4

5 / 16 r5

54

28 of 30

Hex to Binary

29 of 30

Let’s Practice Hex to Binary!

0x D 3 F 2

30 of 30

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?