I
ilhamik
Hi,
Could someone tell me how to convert an number (fixnum or float), say
500000, to a byte array? I need to send that byte array to network.
in Java it was so,
byte[] bytes = new byte[4];
int i = 50000;
bytes[0] = (i & 0xff000000) >> 24; // or (byte)((i >> 24) & 0xFF)
bytes[1] = (i & 0xff0000) >> 16;
bytes[2] = (i & 0xff00) >> 8;
bytes[3] = (i & 0xff);
how is it in ruby world?
Could someone tell me how to convert an number (fixnum or float), say
500000, to a byte array? I need to send that byte array to network.
in Java it was so,
byte[] bytes = new byte[4];
int i = 50000;
bytes[0] = (i & 0xff000000) >> 24; // or (byte)((i >> 24) & 0xFF)
bytes[1] = (i & 0xff0000) >> 16;
bytes[2] = (i & 0xff00) >> 8;
bytes[3] = (i & 0xff);
how is it in ruby world?