Packed Binary Coded Decimal Simulation

written by Teresa Carrigan



Top

WHAT IS IT?

This model demonstrates Packed Binary Coded Decimal character coding. Each decimal digit is converted separately to binary, and stored in one nibble.

Top

HOW IT WORKS

A random decimal number is generated, with 2 to 9 digits, and a random sign of either "+" or "-". The sign is moved to the far right, and then each character is converted to a binary nibble. If the number of nibbles is odd, we add one extra nibble of padding (1111) at the far left. Two nibbles are stored in each byte.

Top

HOW TO USE IT

The setup button generates a decimal number, and initializes variables.

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 demonstrates the next step of the method. It then stops so you can take notes. This is useful when you are first learning the method.

The go button demonstrates 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 sixteen 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 show-again button restarts the demonstration using the same decimal number, so that you can see the same problem several times if you wish.

Top

THINGS TO NOTICE

A packed BCD representation takes more bits than using normal binary representations, but has more flexibility. For example, even if the memory locations and registers are restricted to 64 bit numbers (so a two's complement integer would be limited to 32 bits) a packed BCD number could have an arbitrary number of bytes with two digits per byte.

Top

THINGS TO TRY

Set slow-motion to 0.3, then click go.

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

Allow the user to input a starting decimal number.

Modify so that the packed BCD bit pattern is generated first, and then conversion to decimal is demonstrated.

Modify the model to demonstrate zoned-decimal coding.

Top

NETLOGO FEATURES

Instead of converting each decimal digit to binary every time we process a digit, the different characters and bit patterns are stored in lists once. When we process a character from the decimal number, the lookup procedure simply uses "set n position what from-list report item n to-list"

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). Packed Binary Coded Decimal 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 binary coded decimal, see:
  1. Null, L. and Lobur, J. Essentials of Computer Organization and Architecture, First Edition, Jones and Bartlett, pages 62-63.


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.