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?
-
Show this thread
-
Related: Please send me your best ELI5s on how computers store integerspic.twitter.com/t8RUwcJg3a
2 replies 1 retweet 3 likesShow this thread -
Replying to @southpolesteve
You missed the gradius binary packing migration saved a *ton* of gigabytes! The binary js notation will save you here.
1 reply 0 retweets 1 like -
Replying to @reconbot @southpolesteve
These probably make sense. > 0x10000000 268435456 > 0x00000001 1 This is a single byte, this representation doesn't change anywhere.
1 reply 0 retweets 0 likes -
Replying to @reconbot @southpolesteve
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.
1 reply 0 retweets 0 likes -
Replying to @reconbot @southpolesteve
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>
1 reply 0 retweets 0 likes -
Replying to @reconbot @southpolesteve
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
1 reply 0 retweets 0 likes -
Replying to @reconbot @southpolesteve
And little endian switches the order of the bytes (no real notation for this so lets make one up) > 0xLE00000001000000000000000000000000 1
1 reply 0 retweets 0 likes -
Replying to @reconbot @southpolesteve
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>
1 reply 0 retweets 2 likes
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...
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.