Answers for "int to byte converter"

3

int to byte

int i = 234;
byte b = (byte) i;
System.out.println(b); // -22
int i2 = b & 0xFF;
System.out.println(i2); // 234
Posted by: Guest on October-06-2020
0

converting float to binary 16

import struct
#################### bin32 ################################
# import bitstring
# f1 = bitstring.BitArray(float=0.456789, length=32)
# # f1 = bitstring.BitArray(float=0.456789, length=16)
# print(f1.bin)
# print("0011011101001111")
#################### bin32 ################################

def convertFloatToBin16(x):
    k = struct.pack('>e', x)
    z = ''.join(format(i, '08b') for i in k)
    return str(z)

print(convertFloatToBin16(0.9945678))
Posted by: Guest on October-22-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language