I need convert integer to byte and write byte in file but when i convert a number larger than 128 to byte in convert to a negative number.
I need to use unsigned char but i don’t know how.
in c++ we write unsigned but how is it in java?
I need convert integer to byte and write byte in file but when i
Share
Writing bytes is not a problem, it doesn’t matter whether you use
write(int)orwriteByte(byte)since the data written is still the same whether the byte is signed or unsigned. Reading bytes usingread()also isn’t a problem, because it returns unsigned bytes. Only when you’re reading into a byte array do you need to be careful, because then you have to remember to mask each byte with0xFFwhen you use it.