Here's what I see when I read b.'s dictionary entry: ----------------8<----------------
An atom m=16+k specifies bitwise boolean functions on integer arguments. An argument atom is treated as a list of length w of bits, where w is the word size of the underlying machine. For example, 17 b. specifies bitwise and. Finally, 32 b. specifies rotate, 33 b. specifies shift, and 34 b. specifies signed shift. ----------------8<---------------- This suggests that you can use 33 b. to determine word size of the underlying machine: 0 i.~1&(33 b.)^:a:1 64 This would have given me 32 if I had been using a 32 bit implementation of J. In other words: 64 (33 b.) 1x 0 63 (33 b.) 1x _9223372036854775808 62 (33 b.) 1x 4611686018427387904 Note also that 63 (33 b.) 1x is the smallest integer that can be represented as a 64 bit 2's complement integer. (Are you familiar with the concept of "2's complement"?) Thanks, -- Raul On Sat, Jan 31, 2015 at 10:05 AM, Jon Hough <[email protected]> wrote: > Thanks for the reply. > > So for large ints I should do the shift manually, by multiplying / dividing? > There is no way to use 33 b. ? > > > >> From: [email protected] >> Date: Sat, 31 Jan 2015 09:39:03 -0500 >> To: [email protected] >> Subject: Re: [Jprogramming] Bit Shifting >> >> bit shifting corresponds to multiplying or dividing by powers of two. >> >> shift=: ] * 2 ^ [ >> 1 shift 3x >> 6 >> >> Though you may prefer >> intshift=: ] <.@* 2 ^ [ >> 1 intshift 3x >> 6 >> _1 intshift 3x >> 1 >> >> Thanks, >> >> -- >> Raul >> >> >> On Sat, Jan 31, 2015 at 9:30 AM, Jon Hough <[email protected]> wrote: >> > It seems in J I cannot use the bitshift operator >> > shift =: 33 b. >> > on integers larger than 32 bit unsigned integers (i.e. 2^31). >> > >> > e.g. 1 shift (<: 2^31) has a result >> > but >> > 1 shift 2^31 >> > gives a domain error. >> > >> > Is there anyway to perform bitshifting operations on large (extended ?) >> > integers in J? >> > One possible, although I suppose slow, way is to truncate the binary >> > representation of the integer >> > (i.e. after using #:) and append zeros on the end. >> > >> > ---------------------------------------------------------------------- >> > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
