This is a variation on the ver binary defined a
http://jsoftware.com/pipermail/programming/2011-December/026213.html
effective_magnitude=: (2 * |)^:(-.@-: |)
bit_count=: 2 <.@^. 1>. >./@,@:effective_magnitude
extract_bit=: (%&2 at -&{. , ]) 2&|
binary=: bit_count extract_bit@]^:["1 ,"0
tcr=: 2 | binary
or
tcr=: |@binary
--
Raul
On Wed, Dec 28, 2011 at 3:36 PM, Kip Murray <[email protected]> wrote:
> Now that we can do binary representation without #: or #. please write a
> two's-complement representation tcr without using #: or #. .
>
> tcr _2
> 1 0
> tcr i: 2
> 1 1 0
> 1 1 1
> 0 0 0
> 0 0 1
> 0 1 0
>
> A straightforward two's-complement value tcv explains the two's
> complement representation:
>
> tcv =: ([: (2 p.~ |.) -@{. , }.)"1 NB. two's-complement value
>
> tcv tcr _2
> _2
> tcv tcr i: 2
> _2 _1 0 1 2
>
> Kip
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm