Me, yesterday: You don't need to know computer science to do programming! Me, today: Who are Big Endian and Little Endian? Do they work here?
-
-
You went too deep down the rabbit hole.pic.twitter.com/qFUlItIrAh
-
Should have stopped at the c++ code
- 1 more reply
New conversation -
-
-
You missed the gradius binary packing migration saved a *ton* of gigabytes! The binary js notation will save you here.
-
These probably make sense. > 0x10000000 268435456 > 0x00000001 1 This is a single byte, this representation doesn't change anywhere.
-
A 32 bit number for example is 4 bytes. This is where it gets interesting, node buffers have a wonderful little tool called `.a.writeUInt32LE()` and another called `a.writeUInt32BE()`. Write an unsigned integer to a 4 byte buffer little or big endian style.
-
So we can do it and peak inside. > a = Buffer.alloc(4) // make an empty buffer <Buffer 00 00 00 00> > a.writeUInt32BE(1) // write 1 BIG Endian 4 //bytes written > a <Buffer 00 00 00 01> > a.writeUInt32LE(1) // write 1 little Endian 4 // bytes written > a <Buffer 01 00 00 00>
-
So Big Endian is like a human would write it. Largest byte first, smallest byte last. Similar to how we write numbers, e.g. a 32 bit value of 1 > 0x00000000000000000000000000000001 1
-
And little endian switches the order of the bytes (no real notation for this so lets make one up) > 0xLE00000001000000000000000000000000 1
-
Play around a little and it will click if it hasn't already > a.writeUInt32BE(255) 4 > a <Buffer 00 00 00 ff> > a.writeUInt32LE(255) 4 > a <Buffer ff 00 00 00> > a.writeUInt32BE(256) 4 > a <Buffer 00 00 01 00> > a.writeUInt32LE(256) 4 > a <Buffer 00 01 00 00>
-
This is helpful! Thanks! I've got a situation where some data is encoded in 64 bits so we have to pull in various JS polyfills to deal. But if the only info we actually used is in the first 4 bytes then that might be unnecessary...
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.