Created
July 13, 2014 18:41
Revisions
-
Karsten Becker created this gist
Jul 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ public static BigInteger srl(BigInteger l, int width, int shiftBy) { if (l.signum() >= 0) return l.shiftRight(shiftBy); BigInteger opener = BigInteger.ONE.shiftLeft(width + 1); BigInteger opened = l.subtract(opener); BigInteger mask = opener.subtract(BigInteger.ONE).shiftRight(shiftBy + 1); BigInteger res = opened.shiftRight(shiftBy).and(mask); return res; }