本文介紹了如何在java中將4字節(jié)數(shù)組轉(zhuǎn)換為浮點(diǎn)數(shù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)代表浮點(diǎn)值的 4 字節(jié)數(shù)組.從網(wǎng)絡(luò)讀取字節(jié),例如 3e 3f e3 a0.如何將它從 byte[] 轉(zhuǎn)換為 java 中的浮點(diǎn)數(shù)?
I have a 4 bytes array which represent a float value. The bytes is read from network, for example, 3e 3f e3 a0. How can I convert it from byte[] to float in java?
推薦答案
在 Java 中,char
是 16 位的.如果您的意思是您有 4 個(gè)小端字節(jié)順序的 byte
值,您需要將其轉(zhuǎn)換為 float
您可以使用 ByteBuffer
.
In Java a char
is 16-bit. If you mean you have a 4 byte
values in little endian byte order which you need to convert to a float
you can use ByteBuffer
.
byte[] bytes = { }
float f = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat();
這篇關(guān)于如何在java中將4字節(jié)數(shù)組轉(zhuǎn)換為浮點(diǎn)數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!