Java Bits Convert to BitsNeeded(int n)

Here you can find the source of BitsNeeded(int n)

Description

Bits Needed

License

Open Source License

Declaration

public static byte BitsNeeded(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte BitsNeeded(int n) {
        byte ret = 1;

        if (n-- == 0)
            return 0;

        while ((n >>= 1) != 0)
            ++ret;//from   ww  w  .j  ava2 s .c om

        return ret;
    }
}

Related

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