Dev Helpers
← Back

Write a signed sample to a DataView

Write a signed sample to a DataView using TypeScript.

Open this example in the interactive library

Source code

type Sample = { time: number; value: number };
const samples: Sample[] = [
  { time: 1, value: 2 },
  { time: 2, value: 6 },
  { time: 4, value: 10 },
];
console.log(
  (() => {
    const view = new DataView(new ArrayBuffer(2));
    view.setInt16(0, -3, true);
    return view.getInt16(0, true);
  })(),
);

Sample output

-3