4 ms·
Could you elaborate on these tricks? This sounds interesting. The only thing I'm aware of that's neat in little endian is that if you want the low byte (or wor
by tom_mellior 5y ago
Could you elaborate on these tricks? This sounds interesting.
The only thing I'm aware of that's neat in little endian is that if you want the low byte (or word or whatever suffix) of a number stored at address a, then you can simply read a byte from exactly that address. Even if you don't know the size of the original number.
- kstenerud 5y agoI've posted in some other replies, but a few: - Long addition is possible across very large integers by just adding the bytes and keeping track of the carry. - Encoding variable sized integers is possible through an easy algorithm: set aside space in the encoded data for the size, then encode the low bits of the value, shift, repeat until value = 0. When done, store the number of bytes you wrote to the earlier length field. The length calculation comes for free. - Decoding unaligned bits into big integers is easy because you just store the leftover bits in the next value of the bigint array and keep going. With big endian, you're going high bits to low bits, so once you pass to more than one element in the bigint array, you have to start shifting across multiple elements for every piece you decode from then on. - Storing bit-encoded length fields into structs becomes trivial since it's always in the low bit, and you can just incrementally build the value low-to-high using the previously decoded length field. Super easy and quick decoding, without having to prepare specific sized destinations.