x

Console application usin hamming algorithm

HI All, Im puting here an request, Im not sure is this place ok, but I have to.I need a console apllication for byte correction, using HAMMING ALGORITHM.Can anybody help me on this issue?
more ▼

asked Nov 10, 2010 at 05:43 AM in Default

Gogolo gravatar image

Gogolo
323 22 26 27

(comments are locked)
10|1200 characters needed characters left

3 answers: sort newest
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:)");
            }
        }
    }
}
more ▼

answered Nov 11, 2010 at 12:15 AM

Gogolo gravatar image

Gogolo
323 22 26 27

(comments are locked)
10|1200 characters needed characters left

The source code by Robert H. Morelos-Zaragoza is available [here][2]. It is a console app written in C; it should give you a good start. The code appears to be relatively straighforward to to translate to C# if it needs to be.

[2]: http://the-art-of-ecc.com/2_Short/hamming.c
more ▼

answered Nov 10, 2010 at 04:42 PM

Oleg gravatar image

Oleg
15.9k 2 4 24

Thank you very much, I appreciate your effort. I found some example and I made it something here I will provide you with source code.
Nov 11, 2010 at 12:15 AM Gogolo
(comments are locked)
10|1200 characters needed characters left
Pretty certain this is the wrong place as I dont see any connection to SQL Server in your question. Maybe you will find somewhere on the StackOverflow forums to ask it and have a chance of getting an answer.
more ▼

answered Nov 10, 2010 at 05:55 AM

Fatherjack gravatar image

Fatherjack ♦♦
42.3k 74 78 108

Yeah, I know.. I hoped that I will find answer here...because I found several time very useful answers for my SQL problems. Thank you Fatherjack, I will be back with other SQL questions Take care all
Nov 10, 2010 at 06:16 AM Gogolo
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x20

asked: Nov 10, 2010 at 05:43 AM

Seen: 1109 times

Last Updated: Nov 10, 2010 at 05:43 AM