Dirk Laurie on Fri, 19 Oct 2012 17:58:18 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Word length and number of bits in an integer

I need a routine for the exact smallest value B such that x>>B is zero,
where x is a t_INT.  SInce a may be very large indeed, I coded it thus:

{ bitsin(x) =
   my(w=32*(length(x)-1)); x>>=w;
      while(x, x>>=1; w+=1);

I have two queries:

1. Am I missing some useful builtin function?
2. Can I rely on the words making up x to be 32-bit?
    If not, how do I find out the word length from inside GP?