Thread: Hamming code / even parity help

  1. #1
    Registered User
    Join Date
    Oct 2009

    Hamming code / even parity help

    I'm trying to learn C++ on my own so I figured I'd try to write a program for my data communications class. We were learning about hamming codes and I want to try to make a program that will let me do it automatically instead of on paper. I'd take 8-bit binary numbers from a text file and add 4 parity bits for even parity..

    Quote Originally Posted by for those who don't know about hamming codes
    A parity bit functions by forcing the sum of a some predetermined set of bits to be an even number (called even parity) or an odd number (called odd parity). In this project, we are interested in even parity. To get the desired effect, the parity bit is set to one or zero according to the sum of the specified original bits. If the selected set of original bits sums to an even number, the extra parity bit is set to zero; if it sums to an odd number, it is set to one. Hence, in either case, the sum -- including the parity bit -- will always be an even number.

    For an original message that is 8 bits long, 4 parity bits are added in strategic locations to form a 12-digit message. Each of these additional bits is the parity bit for a different combination of bits in the message, as follows. (Note: for purposes of this problem, bit 1 is defined to be the leftmost bit in the sequence.)

    * Parity bit in position 1 combines with bits at positions 3, 5, 7, 9 and 11.
    * Parity bit in position 2 combines with bits at positions 3, 6, 7, 10 and 11.
    * Parity bit in position 4 combines with bits at positions 5, 6, 7 and 12.
    * Parity bit in position 8 combines with bits at positions 9, 10, 11 and 12.

    Thus, for instance, if the message to be sent is
    then the message to be sent should be augmented with parity bits as follows

    BIT NUMBER 1 2 3 4 5 6 7 8 9 10 11 12
    ORIGINAL MESSAGE 1 0 1 1 0 1 0 0
    SENT MESSAGE 0 0 1 0 0 1 1 1 0 1 0 0

    and it is transmitted as
    Notice that bit 1 is 0 because the sum of bits 3, 5, 7, and 11 is 1 + 0 + 1 + 0 + 0 = 0, which is an even number. And bit 8 is 1 because the sum of bits 9, 10, 11, and 12 is 0 + 1 + 0 + 0 = 1, which is odd.
    I want to take these 3 numbers:

    and output them as these:

    I was thinking of using infile.get() to get each number as a char through a loop(or multiple) and then finding out whether to make an even or odd parity. I'm kinda lost though.

    If anyone has a link to similar code to this that I could look through as an example, that would be helpful as well.

  2. #2
    Registered User
    Join Date
    Apr 2006
    What part are you lost on exactly?

    Determining parity requires an xor operation. In C++ this can be done by using != for bools.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM