5 ms·
I'm not sure I'm understanding you right; a hex character is four bits. To tease a hex character out of a 32 bit int, you'd apply a max of 0000000F, where F is
by NinetyNine 16y ago
I'm not sure I'm understanding you right; a hex character is four bits. To tease a hex character out of a 32 bit int, you'd apply a max of 0000000F, where F is the last four bits.
- euroclydon 16y agoIn the example, if the last four bits are 1100, it's a string. The first seven four-bit quadruplets, plus a bitmask'd version of the last quadruplet (1100) comprised eight sets for four bits. My questions is: how can four bits, if they don't already encode the hex character I'm looking for, be bitmask'd into displaying it, and still be capable of encoding any of the 16 possible hex characters?
- Benjo 16y agoWhere do you see 4 bits? I only see him mention 3 bits: The old jsval representation fit in a 32 bit value, using the 3 lowest bits as a way to tag the value as a particular type. These were called type tags. In the examples given, the lowest three bits are masked to 0s when determining the address. That's a loss of precision, meaning there's no way to represent a pointer to an address that's not modulo 8 == 0. Another way of saying this is that objects must be aligned to 8 byte boundaries. Isn't this a waste of space? Probably not. My guess is very few objects are less than 8 bytes in length, so that space is not really wasted. Even if objects ARE shorter, this is a dynamically typed language, we probably want to keep spare memory anyway, to reduce the chance that adding values to an object will require costly memory allocation.
- wvenable 16y agoIf the last 3 bits are 100 then the value is a pointer to a string. You mask off those 3 bits and you get the address of the string -- you just have to ensure your strings are aligned to 8 byte boundaries.