Here you can find the source of unpackInt(int packedInt, int numBits, int numShiftedLeft)
Parameter | Description |
---|---|
packedInt | a parameter |
numBits | a parameter |
numShiftedLeft | a parameter |
public static int unpackInt(int packedInt, int numBits, int numShiftedLeft)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2013 SKRATCHDOT.COM * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * http://www.eclipse.org/legal/epl-v10.html * // ww w . j av a2 s . co m * Contributors: * JEFF |:at:| SKRATCHDOT |:dot:| COM *******************************************************************************/ public class Main { /** * @param packedInt * @param numBits * @param numShiftedLeft * @return */ public static int unpackInt(int packedInt, int numBits, int numShiftedLeft) { // The comments below assume we are passing in: // packedInt = y010 yyyy // numBits = 3 // numShiftedLeft = 4 // We want to end up with: 0000 0010 int bitsUnshifted = (int) (Math.pow(2, numBits) - 1); // 0000 0111 int bitsShifted = bitsUnshifted << numShiftedLeft; // 0111 0000 int outputValue = packedInt & bitsShifted; // 0yyy 0000 return outputValue >> numShiftedLeft; // 0000 0yyy } }