Java Bits Convert to bitsRequired(double minValue, double maxValue)

Here you can find the source of bitsRequired(double minValue, double maxValue)

Description

computes the required number of bits to represent an range minValue...maxValue / 0..max(minValue,maxValue) In case on of the minValue < 0 also the bit for the sign is included

License

LGPL

Declaration

public static int bitsRequired(double minValue, double maxValue) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*w  w w . j a v a2 s.c om*/
    * computes the required number of bits to represent an range
    * minValue...maxValue / 0..max(minValue,maxValue)
    * In case on of the minValue < 0 also the bit for the sign is included
    *
    */
    public static int bitsRequired(double minValue, double maxValue) {
        long absmax = (long) Math.max(Math.abs(minValue), maxValue) + 1;

        int bits = 64 - Long.numberOfLeadingZeros(absmax);

        if (minValue < 0.0)
            bits++;

        return bits;
    }
}

Related

  1. bits2Numeric(boolean[] in)
  2. bitsArrayToByte(byte[] bits)
  3. bitscanForward(long bitboard)
  4. bitsCleanup(int base, int[] bits)
  5. BitsNeeded(int n)
  6. bitsRequired(int value)
  7. bitsRequiredForFraction(String floatnumber)
  8. bitsString2(byte b)
  9. bitsTo8Bytes(boolean[] bits)