이진 파일 사양에 수식이 있습니다. 스펙은 표제의 다양한 바이트의 의미를 자세히 설명합니다. 특히
, 하나 개의 공식 상태 바이트의 약 2에게 :10 진수 값에서 바이트 배열로의 변환 수식이 작동하지 않습니다.
Byte 1 --> 7 6 5 4 3 2 1 0
Byte 2 --> 7 6 5 4 3 2 1 0
R Roll
If 'R' = 0, Roll Angle not available
If 'R' = 1, Roll Angle = [((Byte 84 & 0x7F)<<8) | (Byte 85) – 900]/10
나는 4.3과 같은 값을 가지고 그것을 사용하여 4.3로 다시 전환 될 수있을 것입니다 두 바이트 등으로 변환 할 필요가 위 공식. 가장 나 퍼즐 부분이 내가 지금까지 가지고있는 인 (900)
을 뺀된다 ...
private byte[] getRollBytes(BigDecimal[] positionData) {
BigDecimal roll = positionData[4];
roll = roll.multiply(BigDecimal.TEN);
roll = roll.add(new BigDecimal(900));
short shortval = roll.shortValue();
byte[] rollBytes = new byte[2];
ByteBuffer headingbuf = ByteBuffer.wrap(rollBytes);
headingbuf.order(ByteOrder.BIG_ENDIAN);
headingbuf.putShort(shortval);
//set the leftmost bit of the two bytes to 'on', meaning data is available
rollBytes[0] = (byte) (rollBytes[0] | (0x80));
//testing the result with my formula doesn't give me the right answer:
float testFloat = (float) (((((rollBytes[0] & 0x7F) <<8) | rollBytes[1]) - 900) /10);
return rollBytes;
}
내가 뭔가 짧고 바이트 사이의 변환에 길을 잃지 생각
상단에있는 값으로 다시 한 번
shortVal
을 계산할 때 한 번 두 번 — 900를 추가 할 것이다 15 비트 (7 비트 + 8 비트)까지 볼 수 있습니다. –@ PeterLawrey 나는 900의 뺄셈을 알아 냈습니다. 당신은 정확합니다, 그것은 15 비트 값으로 발생합니다. – GLaDOS