digitalmars.D.learn - vrp bug?
- Kagamin (9/9) Jun 14 ```
- Forum User (16/26) Jun 14 ```
- Kagamin (1/1) Jun 15 If b<10, `'0'+b` is returned.
```
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?
Jun 14
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`.
Jun 14








Kagamin <spam here.lot>