Here you can find the source of convert(final long value)
Parameter | Description |
---|---|
value | The given value. |
public static BitSet convert(final long value)
//package com.java2s; /**/*from www .j a v a2 s. c o m*/ * Copyright (C) 2012 Ulrich Viefhaus * This file (ByteUtils.java) is from the package utils which is part of Hashchecker. * Hashchecker 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 3 of the License, or * (at your option) any later version. * * Hashmaker and Hashviewer 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 Hashmaker and Hashviewer. If not, see <http://www.gnu.org/licenses/>. * * */ import java.util.BitSet; public class Main { /** * Converts a given Long to a BitSet. * * @param value * The given value. * @return The BitSet representation of the given value. */ public static BitSet convert(final long value) { long tmp = value; BitSet bits = new BitSet(); int index = 0; while (tmp != 0L) { if (tmp % 2L != 0) { bits.set(index); } ++index; tmp = tmp >>> 1; } return bits; } /** * Converts a BitSet to a Long. * * @param bits * The given BitSet. * @return The long representation of the BitSet. */ public static long convert(final BitSet bits) { long value = 0L; for (int i = 0; i < bits.length(); ++i) { value += bits.get(i) ? (1L << i) : 0L; } return value; } }