Right way to show numbers in binary/hex/octal in your opinion?

rempas rempas at tutanota.com
Sun Dec 26 06:16:29 UTC 2021

On Saturday, 25 December 2021 at 22:16:06 UTC, Paul Backus wrote:
> The two's complement representation of a number depends on the 
> width of the integer type you're using. For the number -10, the 
> 16-bit two's complement is `fff6` and the 32-bit two's 
> complement is `fffffff6`.
> The website you link to in your post uses 16 bit integers, but 
> D uses 32-bit `int`s by default. That's where the difference 
> comes from.
Interesting. I want to create a system library but It's funny I 
don't know a lot of low level stuff yet. Tho this also makes it a 
great and even more enjoyable journey :P

> If you implement the first method, users can still get the 
> two's complement representation very easily with (for example) 
> `cast(uint) -10`. On the other hand, if you implement the 
> second method, it's a lot trickier to get the 
> non-two's-complement result. So I think the first method is the 
> better choice here.
That's great! It's much easier to me to just let the first 
behavior anyway that will do! I also posted on [cboard 
forum](https://cboard.cprogramming.com/c-programming/) and I got 
the same answers so this is how we'll do it! Thanks a lot for 
your time and happy holidays!

More information about the Digitalmars-d mailing list