writeUInt16BE

fun writeUInt16BE(value: Number, offset: Number = definedExternally): Double(source)

Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer. Behavior is undefined when valueis anything other than an unsigned 16-bit integer.

This function is also available under the writeUint16BE alias.

import { Buffer } from 'node:buffer';

const buf = Buffer.allocUnsafe(4);

buf.writeUInt16BE(0xdead, 0);
buf.writeUInt16BE(0xbeef, 2);

console.log(buf);
// Prints: <Buffer de ad be ef>

Since

v0.5.5

Return

offset plus the number of bytes written.

Parameters

value

Number to be written to buf.

offset=0 Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2.