Best I can come up with at the moment is
   (([:<.2^.1>.>./@,) (<.@%&2@{.,2&|)@]^:["1 ,"0)

Note that this version does not handle negative numbers.  If I wanted
that, I would probably use (except not split across two lines):

   (([:<.2^.1>.>./@,@:((2 * | - 1:)^:(<&0))) (<.@%&2@{.,2&|)@]^:["1 ,"0)

This is a different result than the #: monad gives, for negative
numbers.  However, this result is compatible with #. and getting the
twos complement representation from this result is trivial.

-- 
Raul

On Tue, Dec 27, 2011 at 7:13 AM, Kip Murray <k...@math.uh.edu> wrote:
> Can you write a verb br which returns the binary representation of y without 
> using #: or #. ?
>
>  br 0
> 0
>  br 2
> 1 0
>  br i. 5
> 0 0 0
> 0 0 1
> 0 1 0
> 0 1 1
> 1 0 0
>  br _13
> |domain error: br
> |       br _13
>
> An inverse I like is
>
>  bv =: (2 p.~ |.)"1 :. br
>
>  bv br i. 5
> 0 1 2 3 4
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to