On Sunday, 14 June 2026 at 09:06:13 UTC, Kagamin wrote:
```
char BitsToChar(in uint bit5)
{
        const uint b=bit5&0x1f;
        return b<10?'0'+b:'a'+(b-10);
}
```
This code can't implicitly convert to char, but a version without parentheses `'a'+b-10` can. Is this intended or I miss something?

```
   (b - 10)
```

has type `uint` and wraps if `b` < 10.

```
   'a' + b - 10
```

is evaluated left to right, `b` is < 32, so `'a' + b` is < 129. Substract 10 and the expression is < 119. It fits in the range of char.

But the whole thing is questionable:

- Drop the `const` in `b`'s declaration and the Error shows up in
     the unparenthesized version, too.

   - try `+127` and `+128` instead of `-10`.
  • vrp bug? Kagamin via Digitalmars-d-learn
    • Re: vrp bug? Forum User via Digitalmars-d-learn

Reply via email to