參照(Double to byte[])它包含了我需要的問題和解決方案。回覆:將Double轉換爲byte []數組
private byte[] convert(Double d) {
byte[] output = new byte[8];
Long lng = Double.doubleToLongBits(d);
for (int i = 0; i < 8; i++) {
output[i] = (byte)((lng >> ((7 - i) * 8)) & 0xff);
}
return output;
}
但我不知道如何/爲什麼它的工作原理,我明白循環將組成Double的8個字節中的每一個分配給數組。但我不明白字節是如何構建的。有人能向我解釋下面的表達嗎?
((lng >> ((7 - i) * 8)) & 0xff);
和爲什麼Double.doubleToLongBits(d);
捲入?
你問運營商做什麼? –