I’ve been fiddling with J internals recently, and finding the need to twiddle
bits. I have a hard time maintaining the numeric b. codes in head, so I threw
together a little utility that lets you say things like:
2b00001000 +. bw 2b11110111
255
2b00001000 *. bw 2b11110111
0
2b00001000 > bw 2b11110111
8
2b00001000 -.@[ bw 2b11110111
_9
3 |. bw 2b11110111
1976
It’s also got a bunch of other features I threw in as I was building it:
primarily other ways of specifying which operation you want, and a way of
looking up the details of any given operation. For details, see the Note
‘EXAMPLES’ at the bottom of the script.
Get it here:
http://www.jsoftware.com/svn/DanBron/trunk/general/bitwise.ijs
Let me know if you find it useful - if enough people can make use of it, I’ll
go through the effort of figuring out how to package and release it as a JAL
addon.
I’m also interested in feedback on the coding style (which will be relevant if
I release it as an addon; public code is held to higher standards).
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm