Well,  doesn't Raul's proposal suit you?  I think it does.

Anyway,  it might also be worth observing (T/bird might
throw in extra lines):
   #:3 14
0 0 1 1
1 1 1 0

and even for some list rather than just a pair of numbers:
   #:3 14 27 93
0 0 0 0 0 1 1
0 0 0 1 1 1 0
0 0 1 1 0 1 1
1 0 1 1 1 0 1

The right-adjustment is done for you.


You can do boolean arithmetic with these in various ways:

   +./#:3 14 27 93   NB. eg OR/ each bit position
1 0 1 1 1 1 1
   #.+./#:3 14 27 93
95
   +./&.:#:3 14 27 93
95
   23 b./3 14 27 93
95


Any use?


Mike



On 20/01/2015 14:05, Jon Hough wrote:
I probably didn't explain very well (I think Also I copy pasted the wrong code 
to boot). In my original example, with 3 and 14,
3 is represented in binary as  1 1 (note any leading zeros are gone)
while 14 is represented as
1 1 1 0

If I want to pad binary represented 3 to be the same as the length of binary 
represented 14, I would want
0 0 1 1

And so I would hope that

  (#: 3) ,: (#: 14)
would give
0 0 1 1
1 1 1 0
(i.e. prepended zeros)

But ,: postpends the padding zeros
i.e.
  (#: 3) ,: (#: 14)
actually gives
1 1 0 0
1 1 1 0

So I am wondering what a nice verb is that does the prepending case.


From: [email protected]
Date: Tue, 20 Jan 2015 08:58:42 -0500
To: [email protected]
Subject: Re: [Jprogramming] Using ,: to prepend bits

I am not quite sure what you are asking.

That said, observe:
    f,:g
1 1 0 0
1 1 1 0
    f,:&.(|."1) g
0 0 1 1
1 1 1 0

Thanks,

--
Raul

On Tue, Jan 20, 2015 at 8:54 AM, Jon Hough <[email protected]> wrote:
This is a little problem I'm having.

Let
f =: #: 3
g =: #: 14

If I do f ,: g

I get

1 0 0 0
1 1 1 0

Here the shorter number , f, has a zero post-pended to match the shape of g.
I would like to find an equivalent verb that prepends the zero.
i.e. , in the case of the above f and g

f some_verb g
gives
0 1 0 0
1 1 1 0

Any help appreciated.

Jon


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
                                        
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4800 / Virus Database: 4257/8964 - Release Date: 01/20/15




---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4800 / Virus Database: 4257/8964 - Release Date: 01/20/15

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to