Creates new Uint32Array from Uint8Array's data - Node.js Data Type

Node.js examples for Data Type:Uint8Array

Description

Creates new Uint32Array from Uint8Array's data

Demo Code

function U8toU32(u8)
{
  var len = u8.length;
  var u32 = new Uint32Array((len >>> 2) + (len % 4 ? 1:0));
  if (len > 1) {
    len--;//from  w w  w .ja  v a  2s  .co m
    for(var i=0; i <= len; i++){    
      u32[i >>> 2] += u8[i] << ((i%4)*8);    
    }
  }else{
    if (len) u32[0]  = u8[0];
  }
  return u32;
}

Related Tutorials