#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Typed arrays and the DataView class


    Hi,

    I am attempting to parse some binary data using the new javascript DataView class that is available in modern browsers.

    But I cannot get it working at all. I tried with the latest Chrome, Safari and IE10-preview browsers. Firefox did not seem to implement DataView at all.

    I am a bit new to javascript so I am probably doing something stupid.

    I tried searching the forum to no avail and the only thing Google drew up was some example from Microsoft for IE10 that seems to indicate what I am doing should have worked.

    This is a minimal example of the code I cannot get to work:

    Code:
            var buffer = new ArrayBuffer(4);
            buffer[0] = 0x01;
            buffer[1] = 0x02;
            buffer[2] = 0x03;
            buffer[3] = 0x04;
            var view = new DataView(buffer);
            alert(view.getUint32(0, true));
    I always get zero but I would have expected a non zero value (67305985 which is 0x04030201 in hex).

    Can anyone explain what is happening here?

    Thanks in advance for any help,
    Stig
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0
    Aha forget that.

    I just realized you cannot set the content of an ArrayBuffer using array-like methods, you actually have to use DataView for that also.

    Sorry about the noise.

IMN logo majestic logo threadwatch logo seochat tools logo