Binary, Quaternary, Octal, Hexadecimal Simulation

written by Teresa Carrigan



Top

WHAT IS IT?

This model demonstrates conversion between any two of the following number bases: two, four, eight, sixteen.

Top

HOW IT WORKS

Any number that is a base which is a power of two can be converted directly to binary, with each digit becoming the same number of bits as the power of two of the base. For example, eight is two cubed, so to convert a number from base eight to base two, each base eight digit is converted directly to three binary bits. The same trick can be used in reverse when starting with base two: group bits from the right into sets of the correct number of bits, then convert each set to a digit in the new base. To convert between bases four, eight, and sixteen, we simply convert to binary first.

This same trick works with any pair of bases that are powers of the same number. It does NOT work in converting between decimal and other bases, unless the other base is 100, 1000, etc.

Top

HOW TO USE IT

If you want examples from a specific base to a specific base: Use the to-base and from-base sliders to set the bases. Now press the setup button. This will generate a random number in the from-base to be converted to the to-base. Note that it is possible to have leading zeroes.

If you do not care which bases are used, click the random button to generate an arbitrary problem.

The slow-motion slider is an easy way to adjust the speed of the display. Set it to zero if you want to show the final result as quickly as possible. 0.3 is a good setting for most purposes.

The step button does the next step of the conversion process. It then stops so you can take notes. This is useful when you are first learning the method.

The go button does all the remaining steps, at a speed determined by the slow-motion slider. This is useful when you do not need to take notes between each step, or do not wish to press the step button five times to get an answer. If you want to pause the demonstration, simply click the go button a second time and it will stop after it finishes the current step. You may then click go a third time to resume.

The quiz button will generate a random problem. Spaces and commas in your answer will be removed, so feel free to use them to help you count the digits. Lower case letters will be automatically changed to upper case.

The show-again button starts the exact problem from the beginning. You may then click either the step button or the go button to see the same demonstration.

Top

THINGS TO NOTICE

When converting to a base that is larger, the number of digits will be smaller. When converting to a base that is smaller, the number of digits will be larger.

Top

THINGS TO TRY

Set slow-motion to 0.3, click random, and then click go.

Set the sliders to a problem type you want to drill, then click setup. Attempt one step at a time on paper, and then click the step button to check that you did that step correctly.

Top

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. Exactly the same tricks are used in conversion.

Allow the user to input a starting digit pattern.

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

Display the decimal equivalent of the digit pattern.

Modify the model to demonstrate direct conversion between base 4 and base 16. Binary is not needed because sixteen is four squared.

Modify the model to demonstrate direct converstion between base 3 and base 9. Since nine is three squared, each base nine digit directly corresponds to two base three digits.

Top

NETLOGO FEATURES

Instead of nested ifelse blocks, taking the log base two of each base was done using: set base-list [ 2 4 8 16 ] set group-by ( 1 + position to-base base-list)

setup-random uses similar list tricks to choose a to-base that is different from the from-base.

one-step uses the NetLogo run command combined with a global integer variable step to run the next step, without needing nested ifelse blocks.

Top

RELATED MODELS

Top

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). Binary, Quaternary, Octal, Hexadecimal Simulation model. Blackburn College, Carlinville, IL.

In other publications, please use: Copyright 2004 by Teresa W. Carrigan. All rights reserved.

Top

FOR MORE INFORMATION

For more information on conversion between bases that are powers of two, see one of the following textbooks:
  1. Dale, N. and Lewis, J. Computer Science Illuminated, Second Edition, Jones and Bartlett, pages 40-41.
  2. Null, L. and Lobur, J. Essentials of Computer Organization and Architecture, First Edition, Jones and Bartlett, page 44.


Home

Applets on this website were written by Teresa Carrigan in 2004, for use in computer science courses at Blackburn College, with the exception of the Fireworks applet. The applets made with NetLogo require Java 1.4.1 or higher to run. The applets made with NetBeans require Java 1.4.2 or higher to run. Applets might not run on Windows 95 or Mac OS 8 or 9. You may obtain the latest Java plugin from Sun's Java site.