Signed Integer Representation Model

written by Crystal Barchet and Teresa Carrigan



Top

WHAT IS IT?

This model demonstrates the three formats for storing a signed decimal integer as an pattern of eight bits: signed magnitude, one's complement, and two's complement.

Top

HOW IT WORKS

First, the sign is separated from the decimal digits. The decimal digits are then converted to unsigned binary, and padded to eight bits. If the sign is positive, then this is the answer, no matter which format is being used. When using signed magnitude, a negative number simply changes the left-most bit from a zero to a one. When using one's complement, a negative number simply inverts each bit. That is, each one becomes a zero, and each zero becomes a one. When using two's complement, first the one's complement is determined, and then we add one to get the answer.

Top

HOW TO USE IT

The setup button generates a random signed decimal integer.

The step button demonstrates the next step, and then stops so you can take notes. This is useful when you are first learning the method.

The go button does every remaining step, at a speed determined by the slow-motion slider. This is useful when you do not need to take notes between each step.

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.

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.5 is a good setting for most purposes.

If the random-format switch is off, then the format demonstrated is the one selected by the format choice box. If the switch is on, then a random format will be chosen.

The format choice box allows you to select which format (signed magnitude, one's complement, two's complement) is demonstrated. The random-format switch must be off for your choice to be used.

The quiz button will generate a random signed decimal integer and ask the user to convert it to either signed magnitude, one's complement, or two's complement. The format used is determined by the format choice box or the random-format switch.

Top

THINGS TO NOTICE

The answer will always have eight bits.

Padding is done before inverting or adding one.

If the decimal number is positive, then all three formats give the same bit pattern, and the left-most bit of the answer will be zero.

If the decimal number is negative, then the three formats will give different bit patterns, but in each case the left-most bit of the answer will be one.

Top

THINGS TO TRY

Set slow-motion to 0.5, select random format, click setup, and then click go.

Set the format to a type you wish to drill, and set random-format off. Click setup. Work each step by hand, and then click the step button to check your answer.

Top

EXTENDING THE MODEL

Allow the user to input the starting decimal integer.

Calculate and display all three formats for the same decimal integer.

Allow the user to specify either eight-bit or sixteen-bit format.

Allow a larger range for the generated decimal integer, and check for overflow.

Top

NETLOGO FEATURES

word is used to concatenate inputs together and reports the result as a string.

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

without-interruption runs all the commands in the block without allowing other agents to "interrupt". That is, other agents are put "on hold" and do not execute any commands until the commands in the block are finished.

Top

RELATED MODELS

Top

CREDITS AND REFERENCES

This model was written by Crystal Barchet and 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: Barchet, C. and Carrigan, T. (2004). Signed Integer Representation Model. Blackburn College, Carlinville, IL.

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

Top

FOR MORE INFORMATION

For more information on representation of negative integers, see one of the following textbooks:
  1. Null, L. and Lobur, J. Essentials of Computer Organization and Architecture, First Edition, Jones & Bartlett, pages 44-55.
  2. Dale, N. and Lewis, J. Computer Science Illuminated Second Edition, Jones and Bartlett, page 59-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.