3 ms·
Oh, that's true of course ... I interpreted it as "rule 0xF is the most important" automatically, heh. Also, I know that hex is cooler, but "0xF" is 33% longer
by unwind 7y ago
Oh, that's true of course ... I interpreted it as "rule 0xF is the most important" automatically, heh.
Also, I know that hex is cooler, but "0xF" is 33% longer than "15", is it really better? :) Of course in this kind of artistic/prosaic text it doesn't matter, express yourself and so on, but I find it really annoying in code.
Some people think that in C, the integer literal 0xff is more "byte-like" than 255, when they are really exactly the same (both have type 'int'). Pet peeve.
- tomxor 7y ago> Some people think that in C, the integer literal 0xff is more "byte-like" than 255, when they are really exactly the same (both have type 'int'). Pet peeve. You are technically correct. However the meaning of the number for purposes of bitwise operation or other relationships to binary can often be more _immediately_ obvious when using hex. Certain regularities that are present in base 2 are also present in base 16 since the base is itself a power of 2. The simplest example is the one you gave 255 = 0xFF = 0b11111111 where the intent is very often a mask. However things get less immediately obvious with larger numbers 0xFFFFFFFF = 4294967295, so it's essentially about clarity, and even for the case of 255 which is obvious to most, it still solidifies the intended meaning. Obviously in this article it's pure geekery and there is no objective defense, but i love it anyway :P
- deleted 6y ago[deleted]
- berti 7y ago> Some people think that in C, the integer literal 0xff is more "byte-like" than 255 When I'm doing bitwise arithmetic, or poking hardware registers, I think in hex. 0xff/255 isn't a good example because that's easy offhand but a lot of other values take longer to "parse" in base 10. It depends on the context whether base 10 or 16 literals are easier to read and parse for humans.
- jkulubya 7y agoNot sure if I’m missing a joke somewhere, but “0xF” is 50% longer (by number of chars) than “15”...no?
- unwind 7y agoHaha yes of course! My bad, thanks.
- agapon 6y agoI think that 0xF is 50% longer than 15 while, of course, 15 is 33% shorter than 0xF.