Profile picture
, 12 tweets, 3 min read Read on Twitter
so, unpack(), won't you?
Many languages have a function like this in their standard library that takes some binary string and extracts out integers and such. It's a handy tool!
But what do you do about endianness?
because as soon as you're dealing with data types over 8 bit you have to worry about byte order. You could just use whatever the computer uses, but often the main reason you want to use something like pack/unpack is because you're talking to another system or a file format
so there's a few ways to do this, and different languages do it in different ways.
Python does it by having you put a special character at the start of your template string, which selects from a few types, like little-endian, big-endian, and some helper alternatives.
but the way perl and php do it is different: Instead of having a pack/unpack that says "all these are in byte-order X", you tell it per-field.
So you can very easily have a big endian field and then a little endian field right next to each other.
so that one up there is PHP, and I'm about to show you perl.
Now, perl is no spring chicken. It's comparatively old, as scripting languages go.
Python and PHP are both 90s languages, Perl is an 80s language.
So it doesn't call them "little" and "big" endian".
"big endian" is often called "network endian" because a lot of network protocols are specified to be big endian.

so it makes sense that they call the big endian versions "network", right? sure.

do they call it x86? intel?
I mean, after all, the intel 8086 is famously little-endian and it's one of the most popular computer architectures of all time...

so yeah, the mnemonic for little-endian 16bit and 32bit numbers in perl's pack is "v for VAX", because of course in 2019 we're still running on minicomputers the size of a washing machine.
ok I'm sorry I was thinking of the later VAX-11/750.
The original VAX-11/780 is quite a bit bigger.
I haven't looked up any other languages.

but I'm hoping to find that ruby calls them "n" (for Nintendo Entertainment System, which used the little-endian 6502) and "a" (for Amiga, which used the big-endian 680x0)
and then it'll turn out Swift calls them "W" (for Wii, which uses a big-endian PowerPC chip) and "C" (for ColecoVision, which uses a little-endian Z80)
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to foone
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!