3

I have an integer 4281644543 in javascript. This is an rgba value that is actually reversed (ff34b5ff but should be ffb534ff) when I read it from a Uint32Array view of an ImageData buffer. I don't know why it comes in reversed.

what bitwise operations do I need to perform to get it into 0xffb534 (without the transparency)

thanks!

leeoniya
  • 1,071
  • 1
  • 9
  • 25
  • 1
    "I don't know why it comes in reversed." It sounds like a Big Endian v. Little Endian problem. I don't know how you are creating your array, but instead of trying to reverse your int, you should see if you can specify the opposite Endian of what you are (implicitly?) using now. – 7stud May 21 '13 at 22:31
  • 1
    If you want to hassle with swapping manually, see here: http://www.umsl.edu/~ewm4g2/articles/endian_swap.html – 7stud May 21 '13 at 22:37
  • i'm not building the original ArrayBuffer myself in this case. `var buf32 = new Uint32Array(imageData.data.buffer);` then just iterating buf32... – leeoniya May 21 '13 at 22:41
  • 1
    found this: http://stackoverflow.com/questions/5320439/how-do-i-swap-endian-ness-byte-order-of-a-variable-in-javascript swap32 got close, `>>> 8` finished the job – leeoniya May 21 '13 at 23:04

0 Answers0