[Node.js] BufferクラスとreadUInt32LE関数
今日じゃないけど、NodeでBufferクラスとreadUInt32LE関数使い、先日のtoString(36)で適当な文字列を作った。
readUInt32LEはLittle endianを用いた関数でBig endian用のreadUInt32BEも対称して存在している。
http://nodejs.org/api/buffer.html#buffer_buf_readuint32le_offset_noassert
16 byteのBufferを用意して、適当な値をつめた後にreadUInt32LE関数で4byteずつ取り出す方法は下記のようになる。
var buf = new Buffer(16); buf = random(); // 適当な値を代入 for(var int = 0; i < 4; i++){ var str = buf.readUInt32LE(i).toString(36); }