This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] FloatToByteArray(float value) { | |
byte[] bytes = new byte[4]; | |
ByteBuffer.wrap(bytes).putFloat(value); | |
return bytes; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final byte[] intToByteArray(int value) { | |
return new byte[] { | |
(byte)(value >>> 24), | |
(byte)(value >>> 16), | |
(byte)(value >>> 8), | |
(byte)value}; | |
} | |
public static byte[] intToByteArray(int value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] doubleToByteArray(double value) { | |
byte[] bytes = new byte[8]; | |
ByteBuffer.wrap(bytes).putDouble(value); | |
return bytes; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void byteArrayToFloat(uint16_t length){//длина массива (если значений несколько*) | |
union | |
{ | |
uint32_t j; | |
float f; | |
} u; | |
for (int i=0;i<length;i+=4){//* | |
u.j = array[i]<<24 | array[i+1]<<16 | array[i+2]<<8 | array[i+3]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hightByte[0] = (uint16_tValue >> 8); | |
lowByte[1] = uint16_tValue & 0xff; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array[0] = (uint32_tValue & 0x000000ff); | |
array[1] = (uint32_tValue & 0x0000ff00) << 8; | |
array[2] = (uint32_tValue & 0x00ff0000) << 16; | |
array[3] = (uint32_tValue & 0xff000000) << 24; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static float bytearray2float(byte[] b) { | |
ByteBuffer buf = ByteBuffer.wrap(b); | |
return buf.getFloat(); | |
} |