Regarding the proposed Binray Literals Deprecation

Don Allen donaldcallen at gmail.com
Tue Sep 13 20:12:10 UTC 2022


On Tuesday, 13 September 2022 at 20:06:55 UTC, Steven 
Schveighoffer wrote:
> On 9/13/22 3:47 PM, Don Allen wrote:
>
>> I would also add that talking about user-friendly/unfriendly 
>> doesn't make a lot of sense unless you state the purpose of 
>> the literal. If I wanted to initialize an int to the number of 
>> states in the US, no one sane would write
>> ````
>> int n_us_states = 0b110010
>> ````
>> If I were defining a mask to extract a field from a hardware 
>> register, I might use a binary literal, though I personally 
>> would use the shifting technique I described in an earlier 
>> post.
>
> Agreed. The purpose is important.
>
> If I wanted to specify an "every third bit set" mask, in hex it 
> would be `0x924924924...`. But in binary it is 
> `0b100100100100...`. The second version is immediately clear 
> what it is, whereas the first is not.
>
> While hex is usually clearer than decimal, it's not always as 
> clear as binary.
>
> BTW, you know how I figured out that 924 pattern? In the 
> easiest way possible of course!
>
> ```d
> writefln("%x", 0b100100100100100100100100);

So you used 0b notation to come up with a justification for 0b 
notation :-)

I do this sort of thing with an HP calculator.

> ```
>
> -Steve




More information about the Digitalmars-d mailing list