Regarding the proposed Binray Literals Deprecation

Steven Schveighoffer schveiguy at gmail.com
Tue Sep 13 21:14:42 UTC 2022


On 9/13/22 4:12 PM, Don Allen wrote:
> 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 used it to figure out what the pattern would be in hex. The arguments 
here are that binary is not needed because hex has it covered.

Like if I get an error on windows of -1073741819, I have to put it into 
hex to see what the true error is (in hex, you can recognize the pattern 
of 0xc0000005)

-Steve


More information about the Digitalmars-d mailing list