checksum

what is the correct implementation of the 8-bit Fletcher algorithm in java?

二次信任 提交于 2020-01-24 10:04:04
问题 i am trying to implement the 8-bit fletcher algorithm. I wrote a piece of code that does that but i am not sure if i understood the algorithm correctly. this is my piece of code: public class TestFletcher { public static void main(String[] argv) { String bin = "10010010101111101110101101110011"; char[] cA = bin.toCharArray(); int ckA = 0, ckB = 0; for (int i = 0; i < cA.length; i++){ ckA += Integer.valueOf(cA[i])/49; ckB += ckA; } System.out.println(ckA); System.out.println(ckB); } the

what is the correct implementation of the 8-bit Fletcher algorithm in java?

一世执手 提交于 2020-01-24 10:04:01
问题 i am trying to implement the 8-bit fletcher algorithm. I wrote a piece of code that does that but i am not sure if i understood the algorithm correctly. this is my piece of code: public class TestFletcher { public static void main(String[] argv) { String bin = "10010010101111101110101101110011"; char[] cA = bin.toCharArray(); int ckA = 0, ckB = 0; for (int i = 0; i < cA.length; i++){ ckA += Integer.valueOf(cA[i])/49; ckB += ckA; } System.out.println(ckA); System.out.println(ckB); } the

Calculate an Internet (aka IP, aka RFC791) checksum in C#

感情迁移 提交于 2020-01-23 12:58:57
问题 Interestingly, I can find implementations for the Internet Checksum in almost every language except C#. Does anyone have an implementation to share? Remember, the internet protocol specifies that: "The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero." More explanation can be found from Dr. Math. There are some efficiency pointers available, but that's

How do I validate a UPC or EAN code?

烈酒焚心 提交于 2020-01-20 14:22:31
问题 I need a C# .NET function to evaluate whether a typed or scanned barcode is a valid Global Trade Item Number (UPC or EAN). The last digit of a bar code number is a computer Check Digit which makes sure the bar code is correctly composed. GTIN Check Digit Calculator 回答1: public static bool IsValidGtin(string code) { if (code != (new Regex("[^0-9]")).Replace(code, "")) { // is not numeric return false; } // pad with zeros to lengthen to 14 digits switch (code.Length) { case 8: code = "000000" +

How to build byte array frame and calculate checksum

北城以北 提交于 2020-01-17 07:52:11
问题 I'm trying to communicate with a serial port as defined in a specification. ser = serial.Serial("/dev/ttyUSB0", baudrate="115200") frame = bytearray([ 0x00, 0x00, #frame control (2 bytes) 0x00, 0x00, #machine id (2 bytes) 0x07, # number of bytes in data field 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, #data field itself 0x00, 0x0A #checksum ]) ser.write(frame) ser.close() The code executes without error, and I am monitoring the same port in a separate script/process. The device is supposed to

Evaluating the differences in CRC-32 implementations

点点圈 提交于 2020-01-15 02:55:12
问题 I have seen many different implementations of the same basic CRC-32 algorithm shown below: int remain; int sbox[SIZESBOX]; int dividend; int bit; for(dividend = 0; dividend < SIZESBOX; dividend++) { remain = dividend << 24; for(bit = 0; bit < 8; bit++) { if(remain & TOPBIT) { remain = (remain << 1) ^ POLYNOMIAL; } else { remain = (remain << 1); } } sbox[dividend] = remain; } Some of them XOR the dividend before going into the sbox. Others XOR before going into the bit loop, and others use

Is it possible to find the CRC32 of a prefix, given only the CRC32 of the whole data?

独自空忆成欢 提交于 2020-01-14 13:00:07
问题 I have to do a lookup in a table, and I have a string identifier and the CRC32 of the string. If there is a miss, I have to decrement the size and lookup for a prefix of the identifier. Therefore, I would need to calculate the checksum of the prefix and repeat the process for each prefix. My C code of this algorithm is something like this: find_prefix(char* string, uint16_t size, uint32_t crc, hash_table_t *hash_table){ do{ if(perform_lookup(string, size, crc, hash_table)==HIT){ return size;

How to calcuate IEEE 802.11 CRC-32 FCS?

纵然是瞬间 提交于 2020-01-14 12:32:16
问题 This is from IEEE Std 802.11-2012 Clause 8.2.4.8 FCS field: I cannot understand the last two paragraphs: What's the meaning by "the initial remainder of the division is preset to all ones", and why we need to do that? What's the meaning by "... the serial incoming bits of the calculation fields and FCS..." ? 回答1: Initializing the CRC to all ones avoids the problem of a string of zeros of any length giving a zero CRC. Read Ross Williams CRC tutorial. 来源: https://stackoverflow.com/questions

CRC Reverse Engineer (Checksum from Machine / PC)

喜欢而已 提交于 2020-01-14 05:29:07
问题 I'm currently looking for on how to determine the CRC produced from the machine to PC (and vice-versa). The devices are communicating using serial communication or RS232 cable. I do only have data to be able for us to create a program to be used for both devices. The data given was from my boss and the program was corrupted. So we are trying for it to work out. I hope everyone can help. Thanks :) 回答1: The sequence to use for the CRC calculation in your protocol is the ASCII string starting