Email or username:

Password:

Forgot your password?
Devine Lu Linvega

Today, @d6 wrote an excellent little guide on how to use negative numbers, aka signed numbers, in #uxn because it's a recurring question on IRC.

The guide also includes implementations of most logical and arithmetic operations.
wiki.xxiivv.com/site/uxntal_si

Uxn doesn't have built-in support for negative integers. However, you can emulate signed numbers by treating some unsigned values as negative.

The first 128 integers (0-127) are represented the same as unsigned and signed, but the latter 128 are different. The basic idea here is that for values greater than #7f (127) we subtract 256 to get their signed value.
4 comments
πŸ‡ΊπŸ‡¦ haxadecimal

@neauoire @d6 The unsigned decimal values given for 0xfd through 0xff in the figure you attached are incorrect (one higher than they should be), though the signed values shown for those same hexadecimal values are correct.
In an n-bit binary representation, a two's complement negative value (MSB set) is equal to the unsigned value minus 2^n, so in an 8-bit two's complement number, 0xff is unsigned 255 , and signed is 255 - 256 = -1.

Devine Lu Linvega

@brouhaha @d6 Oh! right, of course. Thanks for catching that :) Fixed

:luz_cat_ears: meow meow

@neauoire @d6 has anyone done floats? I wanted to do something like that but I was busy

dok

@neauoire @d6 that's the same as two's complement

Go Up