Drahcir
Drahcir

Reputation: 11972

Read 2 bytes as integer

I have a buffer containing the following:

04 01 0c ea c0 a8 00 01 00

The 3rd and 4th bytes (0x0c 0xea) form a port number (3306), but how can I take these bytes and transform them into this integer (3306)?

Upvotes: 1

Views: 3001

Answers (1)

Brad
Brad

Reputation: 163232

I believe you want buf.readInt16LE().

http://nodejs.org/api/buffer.html#buffer_buf_readint16le_offset_noassert

Upvotes: 4

Related Questions