快速业务通道

喘JAVA糞?CRC16丕刮鷹 - 園殻秘壇利

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-18

喘JAVA糞?CRC16丕刮鷹

扮寂:2011-02-23

1?Design

喘JAVA糞?CRC16丕刮鷹 - 園殻秘壇利

2?Code

import java.io.IOException; public class CRC16Checker {        private static int[] index = new int[] { 16, 15, 2, 0 };        private static int[] getBinary(String text) {              StringBuffer num = new StringBuffer();              String s; char ch;              for (int i = 0; i < text.length(); i++) { // Change each char to binary code.                    s = Integer.toBinaryString(text.charAt(i));                    // If the code is less than 8 bit, make it as 8 bit.                    for (int j = 8 - s.length(); j > 0; j--) num.append(0);                    num.append(s);              }              int len = num.length();              int[] code = new int[len];              for (int i = 0; i < len; i++) // Change each 0/1 char to int.                code[i] = Character.getNumericValue(num.charAt(i));              return code;        }        private static String toHex(int[] num) {              StringBuffer hex = new StringBuffer(num.length / 4);              char[] ch = new char[4];              for (int i = 0; i < num.length;) {                // Change each 0/1 int to char.                    ch[0] = Character.forDigit(num[i++], 2);                    ch[1] = Character.forDigit(num[i++], 2);                    ch[2] = Character.forDigit(num[i++], 2);                    ch[3] = Character.forDigit(num[i++], 2);                    // Change each 4-bit-code to hex number.                    hex.append(Integer.toHexString(Integer.parseInt(String.valueOf(ch), 2)));              }              return hex.toString();        } // CRC codes main process        public static int[] makeCRCCodes(int[] sourceCodes, int[] multinomial) {              // The lenght of CRC code is N bits longer than source code. The codes              // from 0 to sourceLength are same as the source. N bits after source              // are the CRC codes. N is decided by the multinomial.              // CRC鷹方怏悳海葎圻鷹海紗貧丕刮鷹鷹海。方怏念何贋慧圻鷹。丕刮鷹贋慧壓方怏              // 恷朔議N了。丕刮鷹海業畳協噐伏撹謹?塀方怏0了崔貧議圷殆。              int sourceLength = sourceCodes.length;              int codesLength = sourceLength + multinomial[0];              int[] crcCodes = new int[codesLength];              // Copy source code from 0 to sourceLength. 申唄圻鷹。              System.arraycopy(sourceCodes, 0, crcCodes, 0, sourceLength);              int

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号