C# Math.ILogB() – Examples
In this tutorial, we will learn about the C# Math.ILogB() method, and learn how to use this method to compute base 2 integer logarithm of a specified number, with the help of examples.
ILogB(Double)
Math.ILogB(x) returns the base 2 integer logarithm of a specified number x
.
Syntax
The syntax of ILogB() method is
Math.ILogB(Double x)
where
Parameter | Description |
---|---|
x | The number whose logarithm is to be found. |
Return Value
The method returns Int32 value.
Example 1 – ILogB(x)
In this example, we will take some double-precision floating-point numbers and find their integer logarithm value with base value of 2, using Math.ILogB() method.
C# Program
using System; class Example { static void Main(string[] args) { Double x; Double result; x = 2; result = Math. ILogB(x); Console.WriteLine($"ILogB({x}) = {result}"); x = 3; result = Math. ILogB(x); Console.WriteLine($"ILogB({x}) = {result}"); x = 4; result = Math. ILogB(x); Console.WriteLine($"ILogB({x}) = {result}"); } }
Output
ILogB(2) = 1 ILogB(3) = 1 ILogB(4) = 2
Please note that ILogB() returns an integer value. Therefore, the precision or decimals points are trimmed out after computing the logarithm.
Conclusion
In this C# Tutorial, we have learnt the syntax of C# Math.ILogB() method, and also learnt how to use this method with the help of C# example programs.