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
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Word length and number of bits in an integer
- From: Dirk Laurie <dirk.laurie@gmail.com>
- Date: Fri, 19 Oct 2012 17:58:11 +0200
- Delivery-date: Fri, 19 Oct 2012 17:58:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Nn66weV292FDSCVJbysKNS+sT3DqOM7gg4flYBoQN+c=; b=ZnQ8tzgE+VjaY/yWOqUjiecSGQtjhGkYJcmIXjW2NKdm23Igr2E1SuISGEfplj7MW9 7vErjOJ0BNLKndXyFL8WkJOMYwoJ8zsQ+3l1jcveBvAsWEvPQQtyPXJmEnURH89WZ/t6 3Hm7HR9Wv71H9UP3OGFUzKk5YQvrZSUyq5Tlh9T+4lirWGHaqZZsGnjRurSqxQk/txRh OrRIKe00MR3NgZC/1CghZicJVKtrB90I9zD6R8MGz0ntZDic/u5r/+RF9GLHSNxfhTRF raW2DThPusb8e3MCitfcHrM2Dttdt6A7C6VnlmTF1EtVjryzyuIwoaI0HnfGce/enExs c3WQ==
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);
w
}
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?