I have such code in PHP:
$b1 = 0x80 | (0x1 & 0x0f);
$file = fopen('message.dat', 'w') or die('cannot create file');
fwrite($file, $b1);
fclose($file);
hexdump shows me:
$ hexdump message.dat
0000000 3231 0039
0000003
The same code in Ruby:
b1 = 0x08 | (0x1 & 0x0f)
File.open('message.dat', 'w') { |file| file.write b1 }
hexdump shows me:
$ hexdump sockets/message.dat
0000000 0039
0000001
b1 should be equal to 9 (decimal). Hex ASCII gives 39. Ok. But PHP gives extra 3231 hex.
Why?
PS. I want to convert PHP code to Ruby. This is WebSocket server. PHP code works properly. File output just only for debugging.