Here you can find the source of toBase_128(BigInteger val)
Parameter | Description |
---|---|
val | a parameter |
public static byte[] toBase_128(BigInteger val)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; import java.util.ArrayList; public class Main { public final static BigInteger BN127 = new BigInteger("127"); /**/*from w w w . j a va 2 s. c o m*/ * This is based on bit shifting (using base128()). * Returns array of bytes. * @param val * @return */ public static byte[] toBase_128(BigInteger val) { ArrayList<Integer> al = base128(val); byte[] result = new byte[al.size()]; for (int k = 0; k < result.length; k++) result[k] = al.get(k).byteValue(); ; return result; } /** * Convert to base 128 (bigendian), using shifts. * @param val * @return */ public static ArrayList<Integer> base128(BigInteger val) { ArrayList<Integer> result = new ArrayList<Integer>(); int part = val.and(BN127).intValue(); val = val.shiftRight(7); result.add(0, new Integer(part)); while (!val.equals(BigInteger.ZERO)) { part = val.and(BN127).intValue(); val = val.shiftRight(7); part += 128; result.add(0, new Integer(part)); } ; return result; } }