Counting in Other Number Bases

WHAT IS IT?

This model demonstrates counting positive integers in any base from two to sixteen, and it also gives the decimal equivalent of each number as it counts. This demonstration will help you understand better how to count in various number bases.

HOW IT WORKS

Each time the current number is incremented, the red arrow passes to the left. When it finds a digit that is one less than the base, it changes that digit to a 0 but continues to the left. When it finds a digit that is two or more less than the base, it changes adds one to that digit and then returns to the start position.

Each patch holding a digit has three variables. The place-value is the decimal amount that a 1 in that position would have. The right-most place value is 1, the next is (base), the third is (base) squared, etc. with each place-value the next power of (base). The digit-value is the digit showing in that position. The current-value of a patch will equal the place-value times the digit-value.

The decimal equivalent of the number is the sum of all the current-values of the patches. If you are familiar with different data representations, this is the unsigned representation.

HOW TO USE IT

Use the number-of-digits slider to set the number of digits that the counter can hold. Use the base slider to set the base. Now press the setup button. This will zero all the digits and initialize the patch variables.

The slow-motion slider is an easy way to adjust the speed of the display so you can watch the digits change as the red arrow moves. Set it to zero if you want to quickly count to a large number.

The increment button adds one to the counter.

The loop button will continuously increment the counter until clicked a second time.

To take a quiz, first select the quiz topic, and then click the quiz button. You may choose to include commas or spaces in your answer to help you count digits; they will be ignored. If you choose "random quiz topic" for your quiz topic, then one of the other possible quiz topics will be chosen for you. When answering a counting quiz question for a base higher than decimal, upper and lower case do not matter.

The base slider sets the base to be used the next time the setup button is pressed. You may choose any base from two to sixteen.

The number-of-digits slider sets the number of digits that the count will hold the next time the setup button is pressed. Possible values range from two to ten.

The setup button consults the base slider and number-of-digits slider, then initializes the counter to that base and number of digits, setting each digit to zero.

THINGS TO NOTICE

While you count, watch the bottom blue line that displays the decimal equivalent. Determine an algebraic expression for the range of possible decimal equivalents, given the number of digits and the base.

THINGS TO TRY

Set the slow-motion to about .10 seconds (or slower) and press the increment button a few times. Watch the red arrow change digits, and notice when it decides no more digits need to be changed.

What happens when all the digits are one less than the base, and you increment again?

EXTENDING THE MODEL

Modify the model to show fixed point representation; that is, specify a given number of digits to the right of the decimal place.

Modify the model so that it counts correctly if the initial number is negative.

Make a "count backwards" model that starts from a large number and decrements instead of incrementing.

Allow the user to input a starting digit pattern.

Allow the user to input a decimal number, and then display the corresponding digit pattern.

NETLOGO FEATURES

"sum values-from patches" is used to easily add all the current value of each patch.

The startup procedure is used to automatically call setup when the program is opened.

"to-report" is used to read the binary number off the patches, and to add commas to a string of bits.

"foreach" is used in converting input to upper case.

CREDITS AND REFERENCES

This model was written by Teresa W. Carrigan, 2004.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

1. this copyright notice is included.
2. this model will not be redistributed for profit without permission from Teresa Carrigan.
Contact Teresa Carrigan for appropriate licenses for redistribution for profit.

To refer to this model in academic publications, please use: Carrigan, T. (2004). Counting in Other Number Bases model. Blackburn College, Carlinville, IL.