Skip to content

Instantly share code, notes, and snippets.

View valentyn-zaitsev's full-sized avatar

Valentyn Zaitsev valentyn-zaitsev

View GitHub Profile
public static float bytearray2float(byte[] b) {
ByteBuffer buf = ByteBuffer.wrap(b);
return buf.getFloat();
}
@valentyn-zaitsev
valentyn-zaitsev / uint32_tToUint8_t.c
Created November 25, 2017 12:02
Uint32_t to uint8_t
array[0] = (uint32_tValue & 0x000000ff);
array[1] = (uint32_tValue & 0x0000ff00) << 8;
array[2] = (uint32_tValue & 0x00ff0000) << 16;
array[3] = (uint32_tValue & 0xff000000) << 24;
@valentyn-zaitsev
valentyn-zaitsev / uint16_tToUint8_t.c
Created November 25, 2017 11:59
Uint16_t to uint8_t
hightByte[0] = (uint16_tValue >> 8);
lowByte[1] = uint16_tValue & 0xff;
@valentyn-zaitsev
valentyn-zaitsev / byteArrayToFloat.c
Created November 25, 2017 11:56
Byte array to Float
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];
@valentyn-zaitsev
valentyn-zaitsev / doubleToByteArray.java
Created November 25, 2017 09:29
Double to Byte array
public static byte[] doubleToByteArray(double value) {
byte[] bytes = new byte[8];
ByteBuffer.wrap(bytes).putDouble(value);
return bytes;
}
@valentyn-zaitsev
valentyn-zaitsev / intToByteArray.java
Last active April 9, 2025 00:42
Int to Byte array (java)
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) {
@valentyn-zaitsev
valentyn-zaitsev / floatToByteArray.java
Created November 25, 2017 08:02
Float to Byte array (java)
public static byte[] FloatToByteArray(float value) {
byte[] bytes = new byte[4];
ByteBuffer.wrap(bytes).putFloat(value);
return bytes;
}