by If you take a look into the time line, there was a reply by @ScottSelikoff (funny comment of course) who stated 42 as the answer to life, the universe and everything to the magic method which has been followed by Lukas Eder: For what percentage of longs would that be the correct result?

Here are some exemplary values for the type Integer: A very naive way of trying to solve that question would be to write code like this: The first line will create 2^64 which is equal to 100% and the BigDecimal.valueOf(v).divide(pow).multiply(BigDecimal.valueOf(100L)) will just calculate the percentage of the value (number of values for appropriate bit count) of the resulting map which contains the number.

So it means for bitCount=16 we have 601,080,390 values which are 13,995 percent of all integer values.

By expressing that like this: You can calculate that via WolframAlpha and the result is: 601080390 which is exact the number in the above example.

Related Articles