Here you can find the source of bits(long value, int sb, int eb)
Parameter | Description |
---|---|
value | The bitmask |
sb | The starting bit (inclusive) |
eb | The ending bit (inclusive), must be < sb |
public static long bits(long value, int sb, int eb)
//package com.java2s; /*//from w w w .j av a 2 s . co m * Copyright (C) 2011 Sony Ericsson Mobile Communications AB * Copyright (C) 2012-2013 Sony Mobile Communications AB * * This file is part of ChkBugReport. * * ChkBugReport is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * ChkBugReport is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ChkBugReport. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Extracts a bit range from a long value * @param value The bitmask * @param sb The starting bit (inclusive) * @param eb The ending bit (inclusive), must be < sb * @return The extracted value */ public static long bits(long value, int sb, int eb) { value >>>= eb; sb -= eb - 1; long mask = (1L << sb) - 1; value &= mask; return value; } }