gpt4 book ai didi

java - 用java计算LRC

转载 作者:行者123 更新时间:2023-12-01 19:16:53 25 4
gpt4 key购买 nike

我想计算以下消息的 LRC:

T = 0101 0100P = 0101 00001 = 0011 00012 = 0011 0010Starting with 0x00 as the initial byte.0 XOR ‘T’:         0000 00000101 0100Result, LRC =    0101 0100LRC XOR ‘P’:    0101 0100                        0101 0000Result, LRC =    0000 0100LRC XOR ‘1’:    0000 0100                        0011 0001Result, LRC =    0011 0101LRC XOR ‘2’:    0011 0101                        0011 0010Result, LRC =    0000 0111

The code i have tried so far is shown below:

public class TexttoBinary {

private static final int maxBytes = 1;

public static int convert(char number) {

// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Type the number to parse: ");
//int number = Integer.parseInt(in.readLine());
int Bit;
//char number = '1';
//UInt8 i;
String result = "";
for (int i = maxBytes * 7; i >=0; i--) {
Bit = 1 << i;
if (number >= Bit) {
result += 1;
//System.out.println(result);
number -= Bit;
} else {
result += 0;
}
}
System.out.println(result);
return Integer.parseInt(result);
}
public static void main(String args[]){
String msg ="TP12";
char[] toCharArray = msg.toCharArray();
char lrc=0;
for(int i=0;i<toCharArray.length;i++)
lrc ^=convert(toCharArray[i]);
System.out.println((byte)lrc);
}

}

我得到的输出是不同的。我现在该怎么办?

最佳答案

假设您正在谈论纵向冗余检查;如有疑问,check you algorithm against published examples .

Here's one in Java ,这看起来和你的很不一样。也许您尝试使用 DeMorgan 定理来优化 LRC,但很有可能它在此过程中发现了错误。

关于java - 用java计算LRC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6221886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com