locked
How to pass from CRC Kermit to CRC Xmodem RRS feed

  • Question

  • Hi, I am trying to créate a CRC Xmodem calculator. I write a number, and the program is supposed to generate the CRC Xmodem 4 character code of that number.

    So far, I managed to calculate the CRC Kermit and the CRC-16, but I am not able to find how to calculate the CRC Xmodem number. Thanks in advance for the help.

    string input_number;
                int input_number_length;
                string stringArray = "";
                string[] str_parsed = new string[4096];
                int[] input_bytes = new int[4096];		
                int stringStart = 0;
                int initial_crc = 0x0000;
                int initial_Coefficient = 0x8408;
                int lessSignificantB, crcByteA, crcByteB;
                
                input_number = textoTrama.Text;
                
                if (input_number.Length % 2 != 0)
                {
                	input_number = input_number + " ";
                }
                
                input_number_length = input_number.Length/2;
                
                //************* Divide the string *************
                
                for (int k = 0; k<input_number_length; k++)
                {
                	stringArray = input_number.Substring(stringStart, 2); 
                	str_parsed[k] = stringArray;							
                	stringStart = stringStart + 2;
                }
    
                //******* Conversion from hex string to int *******
                
                for (int i = 0; i < input_number_length; i++) 
                {
                 input_bytes[i] = Int32.Parse(str_parsed[i],         NumberStyles.HexNumber); //Pasa el array Hex a array Int
                	
                }
                
    			//***************** Algorithm ******************
    			
                for (int i = 0; i < input_number_length; i++)
                {
                	initial_crc = initial_crc ^ input_bytes[i];
                    for (int j = 0; j < 8; j++)
                    {
    	                lessSignificantB = initial_crc & 0x0001;  // Mask of LSB
    	                initial_crc = initial_crc >> 1;
    	                initial_crc = initial_crc & 0x7FFF;
    	                if (lessSignificantB == 1)
    	                {
    	                	initial_crc = initial_crc ^ initial_Coefficient;
    	                }
                    }
    			}
                
                crcByteA = initial_crc & 0x00FF;
                crcByteB = (initial_crc >> 8) & 0x00FF;
    
                miCRC.Text = crcByteA.ToString("X") + crcByteB.ToString("X");

    Tuesday, February 10, 2015 7:46 AM

Answers

  • Hi Manolo_007,

    Thank you for posting in the MSDN forum.

    Thank you for posting in the MSDN forum. It seems that it is not the correct forum for this issue, since this forum is to discuss Visual Studio IDE. I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

    Maybe the language developing forum would be better for you.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral%2Ccsharpgeneral%2Cvcgeneral&filter=alltypes&sort=lastpostdesc

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Dave PatrickMVP Friday, February 13, 2015 3:47 AM
    • Marked as answer by Just Karl Friday, February 20, 2015 6:56 PM
    Friday, February 13, 2015 1:23 AM