I think you meant to use #write_byte
. The method you’re using is writing the binary representation of a UInt16
, which takes two bytes to represent each value. However since they’re all less than 255, the second byte technically isn’t needed and is correctly zero.
If these values are indeed intended to be used to represent bytes, consider using Bytes - Crystal 1.8.2. This would allow you to simplify your logic to essentially just:
bytes = Bytes[0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1]
File.open("test.old", "wb") do |file|
file.write bytes
end