Dave's Brain

Browse - Programming Tips - How can I make an array of unsigned 32-bit numbers?

Date: 2014oct15
Language: javaScript

Q.  How can I make an array of unsigned 32-bit numbers?

A.  As it turns out there is a built-in class for that.

Example 1:

var a = new Uint32Array(256); // Make an empty array of 256 entries a[100] = 12; // As you'd expect... set element 100 to 12. console.log('value='+a[100]); // print value of element 100
Example 2:
// Create an 4 element array with values 100, 200, 400, 800 var a = new Uint32Array([100, 200, 400, 800]);
Warning! the array does not grow. So this will NOT work:
var a = new Uint32Array(); a[5] = 44; // Does not work.
You can use the set() member to change the array after its created. Normally numbers in javaScript are 64-bit floats.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.