You’re actually mixing up two completely different concepts.
A binary number is just a number expressed in base-2 notation. Apart from the digits, everything else is exactly the same as in other number systems like decimal or hexadecimal. For example, negative numbers are obviously prefixed by a minus sign.
The decimal number
-1 expressed as binary number is also just
-1. The hexadecimal value
FFFF FFFF FFFF FFFF is just a simple number, equivalent to decimal
These conversions are all handled by
#to_s methods on Crystal’s number types.
When you expect
FFFF FFFF FFFF FFFF to mean
-1, you’re actually talking about a integer data type representation which uses the two’s complement to encode a signed number. This is just a specific data format used to represent arbitrary values (in this case: a signed integer) as binary data.
This encoding is usually handled by Crystal internally and you don’t actually see it, but it can be explicitly used with the