⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc.java

📁 JRed is a 100% Java implementation of the IrDA infrared communications protocols. JRed lets you beam
💻 JAVA
字号:
/*
**************************************************************************
** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/irlap/Crc.java,v 1.1.1.1 2000/07/05 04:41:52 mpatters Exp $
**
** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
**
** This file is part of JRed, a 100% Java implementation of the IrDA
** infrared communications protocols.
**
** This file may be distributed under the terms of the Synchrona Public
** License as defined by Synchrona, Inc. and appearing in the file
** LICENSE included in the packaging of this file. The Synchrona Public
** License is based on the Q Public License as defined by Troll Tech AS
** of Norway; it differs only in its use of the courts of Florida, USA
** rather than those of Oslo, Norway.
**************************************************************************
*/
package com.synchrona.jred.irlap;

import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Generate a 16-bit CRC-CCITT
 */
class Crc {
	public static final int HDLC_POLYNOMIAL = 0x8408;

	public static void main(String [] astrArgs) {
		try {
			PrintWriter p = new PrintWriter(new FileOutputStream("CrcTable.java"));
			Crc.writeTable(p);
			p.close();
		} catch ( Exception e ) {
			System.err.println(e);
			e.printStackTrace(System.err);
		}
	}

	public static void writeTable(PrintWriter out) throws IOException {
		out.println("public class CrcTable {");
		out.print("\tpublic static short ayFcsTable[] = {");

		int b;
		int i;
		int v;
		for ( b = 0; ; ) {
			if ( 0 == (b % 8) )
				out.print("\n\t\t");

			v = b;
			for ( i = 8; i-- > 0; ) {

				if ( 0 != (v & 1) ) {
					v = (v >> 1) ^ HDLC_POLYNOMIAL;
				} else {
					v = v >> 1;
				}
			}
			out.print("(short) " + (v & 0xFFFF));
			if ( ++b == 256 ) 
				break;
			out.print(",\t");
		}

		out.println("\n\t};\n}");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -