# Hamming Code Simulation

## WHAT IS IT?

This model demonstrates storing of bit patterns using Hamming SEC, even parity, with up to eight data bits.

## HOW IT WORKS

First a random bit pattern is generated, of the length specified by the number-of-digits slider. Extra bits known as check bits are added so that they occupy positions 1, 2, 4, and 8. If there will be no data bits past a check bit, then that check bit is not needed.

Each position is then marked with the binary equivalent of the position number. This will help us determine easily which bits are checked by which check bit. Each check bit has a single one in the binary equivalent of its position number, and checks all bits that have a one in that same place in the binary equivalent. Each check bit will force its own group to have even parity.

## HOW TO USE IT

The setup button generates a random bit pattern, of the length specified by the number-of-digits slider.

The random button generates a random number of bits, and then uses that to generate a random bit pattern.

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 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.

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 number-of-digits slider determines the number of data bits to be generated when the setup button is pressed.

## THINGS TO NOTICE

After the first two check bits, each additional check bit allows at least double the number of data bits before another check bit is required.

Although there are numerical methods for determining the number of check bits needed, we know that the check bits always go in positions that are powers of two, and if there are no data bits past a check bit position, that check bit is not needed. This gives us an easy way to determine the number of check bits needed.

The group of bits checked by a check bit is easily determined by looking at the binary equivalent of the position number. Each bit in that group will have a 1 in the same place.

## THINGS TO TRY

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

Set the number-of-digits slider to the number of data bits you wish to drill, and click setup. Work each step by hand, and then click the step button to check your answer.

## EXTENDING THE MODEL

Allow the user to input the starting bit pattern.

Allow for more than eight data bits.

Modify the model to use a Hamming double-error-correcting code.

## NETLOGO FEATURES

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

The arrow uses "other-BREED-here" to interact with the yellow bits.

## 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). Hamming Code Simulation Blackburn College, Carlinville, IL.