1

I need a console application for byte correction, using Hamming algorithm. Can anybody help me on this issue?

Input word would be for example: 11100100

Qiu
  • 5,651
  • 10
  • 49
  • 56
Gogolo
  • 128
  • 1
  • 11

2 Answers2

1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Bits
{
    class Program
    {
        static void Main(string[] args)
        {
            string NrBinary;
            int pp, Key, number;
            double x, y;
            Console.WriteLine("Give binary value till 8 bit: ");
            NrBinary = Console.ReadLine();
            if (NrBinary.Length <= 8)
            {
                if (NrBinary.Length == 1) NrBinary = "0000000" + NrBinary;
                if (NrBinary.Length == 2) NrBinary = "000000" + NrBinary;
                if (NrBinary.Length == 3) NrBinary = "00000" + NrBinary;
                if (NrBinary.Length == 4) NrBinary = "0000" + NrBinary;
                if (NrBinary.Length == 5) NrBinary = "000" + NrBinary;
                if (NrBinary.Length == 6) NrBinary = "00" + NrBinary;
                if (NrBinary.Length == 7) NrBinary = "0" + NrBinary;


                pp = NrBinary.Length;
                number = Convert.ToInt32(NrBinary);
                Console.WriteLine("PP = " + pp);

                for (Key = 0; Key < pp; ++Key)
                {
                    x = Math.Pow(2, Key) - 1;
                    y = pp + Key;

                    if (x >= y)
                    {
                        goto Mess;
                    }
                }
            Mess:
                Console.WriteLine("Controled bit needed Key = " + Key + "\n");

                int[] parity = new int[pp];
                int[] DI = new int[pp];
                int[] CI = new int[Key];

                DI[0] = number % 10;
                DI[1] = (number / 10) % 10;
                DI[2] = (number / 100) % 10;
                DI[3] = (number / 1000) % 10;
                DI[4] = (number / 10000) % 10;
                DI[5] = (number / 100000) % 10;
                DI[6] = (number / 1000000) % 10;
                DI[7] = (number / 10000000) % 10;

                CI[0] = DI[0] ^ DI[1] ^ DI[3] ^ DI[4] ^ DI[6];
                CI[1] = DI[0] ^ DI[2] ^ DI[3] ^ DI[5] ^ DI[6];
                CI[2] = DI[1] ^ DI[2] ^ DI[3] ^ DI[7];
                CI[3] = DI[4] ^ DI[5] ^ DI[6] ^ DI[7];

                Console.WriteLine("\n  = " + CI[0] + "" + CI[1] + "" + CI[2] + "" + CI[3] + "\n");
                Console.Write("Bit with Hamming code: ");
                Console.WriteLine(DI[7] + "" + DI[6] + "" + DI[5] + "" + DI[4] + "" + CI[3] + "" + DI[3]
                + "" + DI[2] + "" + DI[1] + "" + CI[2] + "" + DI[0] + "" + CI[1] + "" + CI[0]);
            }
            else
            {
                Console.WriteLine("\n\n 8 bit character maximaly:)");
            }
        }
    }
}
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
Gogolo
  • 128
  • 1
  • 11
  • You should probably add this code as a update to your question rather than an answer. And you say you didn't get stuck - does this code work for you? If not, what's not working? – The Archetypal Paul Nov 11 '10 at 08:42
  • it works OK, but if you think that something can be improved.. you are welcome to do that.. – Gogolo Nov 11 '10 at 09:22
0

Under the assumption this is homework, here's a pointer to the general algorithm. Have a go yourself, post what you've tried and the specific problems you're having, and people might help you out.

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
  • Yeah, you have a right, this is my forst post here, and I dont have a clue about how to ersolve this, and the badest thing is that I didnt even started to do something, coz I have no clue how to even start... If its anyone who have something about this issue, I would appriciate it. – Gogolo Nov 10 '10 at 14:38
  • Do you know how to write console apps? If so, then that + the Wikipedia page should be enough to get started. – The Archetypal Paul Nov 10 '10 at 14:39
  • What are you needing to do? take a sequence of bytes and output the hamming code? Or take in some hamming code (possibly with errors) and detect/correct errors? What don't you understand about the algorithm on the Wikipedia page? – The Archetypal Paul Nov 10 '10 at 15:09
  • 1
    No. And you didn't answer my questions. SO isn't for getting people to do your homework for you. If you've tried and you're stuck, then show what you've done and ask for specific help. If you can't even get started, you need to talk to your instructors, not try and fake it by passing off others work as your own – The Archetypal Paul Nov 10 '10 at 15:22
  • i tried and I didn't stuck..and I will provide you with source code here.. If you have any better Idea please let me know.. – Gogolo Nov 11 '10 at 08:20