Java Bits Convert to bitsRequiredForFraction(String floatnumber)

Here you can find the source of bitsRequiredForFraction(String floatnumber)

Description

Determines in a Float String how much bits a necessary to represent the given Fraction with less error than the string.

License

LGPL

Declaration

public static int bitsRequiredForFraction(String floatnumber) 

Method Source Code

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

public class Main {
    /**//from   w  w  w  .j  a  v  a 2 s .  c  om
     * Determines in a Float String how much bits a necessary to represent the
     * given Fraction with less error than the string.
     * It is not checked if the float, is a valid float representation.
     *
     */
    public static int bitsRequiredForFraction(String floatnumber) {
        if (floatnumber.contains("eE")) {
            System.out.println("e float represenation not yet supported!");
        }
        int pos = floatnumber.indexOf(".");
        /* log_2 (10) = 2.30... That means that many bits are enough per decimal digit */
        return (int) Math.ceil((floatnumber.length() - pos - 1) * 2.31);
    }
}

Related

  1. bitscanForward(long bitboard)
  2. bitsCleanup(int base, int[] bits)
  3. BitsNeeded(int n)
  4. bitsRequired(double minValue, double maxValue)
  5. bitsRequired(int value)
  6. bitsString2(byte b)
  7. bitsTo8Bytes(boolean[] bits)
  8. bitsToBase64(byte data)
  9. bitsToDouble(String bits, double min, double max, int splits)