[QUESTION] Usage of negative number notations on unsigned numbers.
Karthik B K
karthik.bk at incoresemi.com
Mon Nov 27 21:28:03 PST 2023
On 27/11/23 19:16, Andreas Schwab wrote:
> On Nov 27 2023, Karthik B K wrote:
>
>> What's the encoding of (2^32-1)UL and (2^64-1)UL ?
> A value does not have an encoding. Only a memory location does.
>
So does a register (container of bits), and a type (signed, unsigned,
float).
The "encoding" is dependent on the "container" (reg or mem) and "type"
(signed, unsigned, float).
The same bits (11...11) would reflect very different values (-1, 2^32-1,
quiteNaN).
The container of (2^32-1) is UInt. 32b unsigned integer. -1 cannot be
represented in a 32b unsigned int.
I'm trying to say, that the unary operator (-) in the expression (-1UL)
is an integer arithmetic operator.
The unary operator (-) when applied to an unsigned type, results in the
_negative_ of it's (promoted as per _usual arithmetic conversions_)
operand, which in this case, is a signed integer.
The result will retain this type. Are we assuming an implicit cast ?
This looks like an illegal set of operations to create the bit pattern
we desire (11...11) for an unsigned int.
Simply put, a -1 in a UL is an oxymoron. Don't you think ?
Please correct me if I'm wrong.
karthik.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/opensbi/attachments/20231128/41bd0218/attachment.sig>
More information about the opensbi
mailing list