Regarding the proposed Binray Literals Deprecation

Walter Bright newshound2 at digitalmars.com
Sat Sep 10 18:32:26 UTC 2022


On 9/10/2022 8:21 AM, 0xEAB wrote:
> But if we assume one’s working with binary flags or something similar (which 
> probably was the reason to use binary literals in the first place), why would we 
> write them in a different notation?

I use binary flags all the time:

     enum Flag  = {
       CARRY    =    1,
       SIGN     =    2,
       OVERFLOW =    4,
       PARITY   =    8,
       ZERO     = 0x10,
       ... }

but as mnemonics.


> To give an example:
> I can’t translate hex literals to their binary form in my head (in reasonable 
> time).

I understand. I suppose it's like learning to touch-type. Takes some effort at 
first, but a lifetime of payoff. There's no way to avoid working with binary 
data without getting comfortable with hex.

(In 8th grade I took a 2 week summer school course in touch typing. The 
typewriters were mechanical monsters, you really had to hammer the keys to get 
it to work, but that helped build the muscle memory. Having a lifetime of payoff 
from that was soooo worth the few hours.)

Other things worth taking the time to get comfortable with:

1. 2-s complement arithmetic
2. how floating point works
3. pointers


> And I never even had to do so – except for an exam or two at school.
> Wanna know how I did it? – I wrote down the `0=0000`…`1=0001`…`F=1111` table…

That's how I learned the multiplication tables. I'd write out the matrix by hand.


More information about the Digitalmars-d mailing list