September 13, 2022

On 9/13/22 2:07 PM, wjoe wrote:

>

On Saturday, 10 September 2022 at 02:22:53 UTC, Walter Bright wrote:

>

Hex values are far easier to read, too. Have you ever put the tip of your pencil on the screen to count the number of 1's? I have. Binary literals are user unfriendly.

That's true only if you're working with hex values.

Besides, I've had to use the tip of a pencil to count Fs in hex values.
Are you saying that hex is user friendlier when dealing with decimal values, too ?

I've used the tip of a pencil to write out what the real bits are of a hex literal, because I can never remember what all of them actually mean.

-Steve

September 13, 2022
On 9/13/2022 11:07 AM, wjoe wrote:
> Besides, I've had to use the tip of a pencil to count Fs in hex values.

So have I. But I have only 1/4 as many digits to count, and don't need to if there are 6 or fewer digits.


September 13, 2022
On Tuesday, 13 September 2022 at 18:50:01 UTC, Walter Bright wrote:

>
> So have I. But I have only 1/4 as many digits to count, and don't need to if there are 6 or fewer digits.

Nibble is four digits.
September 13, 2022
On Tuesday, 13 September 2022 at 13:52:43 UTC, Don Allen wrote:
> [snip]
> I was talking about language complexity, as was Walter. I thought that was quite clear and still do.
>
> [snip]

I think Walter has referenced both and it's not always clear which ones he is referring to. That's part of the confusion.

I can't recall your arguments, to be honest.
September 13, 2022

On Tuesday, 13 September 2022 at 19:21:11 UTC, Max Samukha wrote:

>

On Tuesday, 13 September 2022 at 18:50:01 UTC, Walter Bright wrote:

>

So have I. But I have only 1/4 as many digits to count, and don't need to if there are 6 or fewer digits.

Nibble is four digits.

And your point is?

One hex digit represents 4 binary digits. What Walter said is correct.

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.

September 13, 2022

On Tuesday, 13 September 2022 at 19:47:43 UTC, Don Allen wrote:

>

On Tuesday, 13 September 2022 at 19:21:11 UTC, Max Samukha wrote:

>

On Tuesday, 13 September 2022 at 18:50:01 UTC, Walter Bright wrote:

>

So have I. But I have only 1/4 as many digits to count, and don't need to if there are 6 or fewer digits.

Nibble is four digits.

And your point is?

My point has been restated multiple times in this thread by several people: if the binary represents bit flags and is grouped with a dash in nibbles, it is easier to read than a hex. You count bits, not hex digits, and there is no need to count more than 4.

September 13, 2022

On Tuesday, 13 September 2022 at 19:56:22 UTC, Max Samukha wrote:

>

My point has been restated multiple times in this thread by several people: if the binary represents bit flags and is grouped with a dash in nibbles, it is easier to read than a hex. You count bits, not hex digits, and there is no need to count more than 4.

s/dash/underscore

September 13, 2022

On Tuesday, 13 September 2022 at 19:56:22 UTC, Max Samukha wrote:

>

My point has been restated multiple times in this thread by several people: if the binary represents bit flags and is grouped with a dash in nibbles, it is easier to read than a hex. You count bits, not hex digits, and there is no need to count more than 4.

You are right.

Furthermore complexity is not reduced by removing literals, consider if you use 5+ languages, and every language has it's own include to enable literals, then you need to remember 5 different includes. (std.conv really makes no sense what if you don't even use phobos?)

September 13, 2022

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!

writefln("%x", 0b100100100100100100100100);

-Steve

September 13, 2022

On Tuesday, 13 September 2022 at 19:56:22 UTC, Max Samukha wrote:

>

On Tuesday, 13 September 2022 at 19:47:43 UTC, Don Allen wrote:

>

On Tuesday, 13 September 2022 at 19:21:11 UTC, Max Samukha wrote:

>

On Tuesday, 13 September 2022 at 18:50:01 UTC, Walter Bright wrote:

>

So have I. But I have only 1/4 as many digits to count, and don't need to if there are 6 or fewer digits.

Nibble is four digits.

And your point is?

My point has been restated multiple times in this thread by several people: if the binary represents bit flags and is grouped with a dash in nibbles, it is easier to read than a hex. You count bits, not hex digits, and there is no need to count more than 4.

I'm aware of those arguments. It wasn't at all clear how your terse comment related to them.

Yes, if you are concerned with individual bits, then binary representation is obviously more natural than hex (or octal or decimal). But depending on your purpose, other representations may be more natural than 0b. I gave an example in a previous post and therefore won't repeat.