[Issue 20535] std.format: %b, %o, %x and %X on negative integers gives wrong result

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 3 18:54:29 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20535

Bolpat <qs.il.paperinik at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |qs.il.paperinik at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from Bolpat <qs.il.paperinik at gmail.com> ---
Reading https://dlang.org/phobos/std_format.html#formattedWrite section
'b','d','o','x','X':
> [...] If the argument is a signed type and the FormatChar is d it is converted to a signed string of characters, otherwise it is treated as unsigned. [...]

So, clearly, the intended result for negative numbers is not a minus sign and
magnitude, but two's complement.

--


More information about the Digitalmars-d-bugs mailing list