Monadic #: is lossy. It will represent different integers in the same
array with the same result:
$#:i:4
9 3
$~.#:i:4
8 3
For backwards compatibility reasons, this should probably not be changed.
Nevertheless, a non-lossy variant can also be useful:
twosC=: #:~ 2 #~ 1 + {:@$@#:
The name is based on this idea: https://en.wikipedia.org/wiki/Two%27s_complement
$twosC i:4
9 4
$~.twosC i:4
9 4
Basically, each integer gets an extra bit in the result. The first bit
for positive integers will always be 0. The first bit for negative
integers will always be 1.
FYI,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm