C# Math.ScaleB() – Examples

In this tutorial, we will learn about the C# Math.ScaleB() method, and learn how to use this method to scale a given number with 2 by n times, with the help of examples.

ScaleB(Double, Int32)

Math.ScaleB() returns x * 2^n computed efficiently.

Syntax

The syntax of ScaleB(x, n) method is

</>
Copy
Math.ScaleB(Double x, Int32 n)

where

ParameterDescription
xA double-precision floating-point number that specifies the base value.
nA 32-bit integer that specifies the power.

Return Value

The method returns Double value.

Example 1 – ScaleB(Double, Int32)

In this example, we will take some combinations for x, n and find the value of x*2^n using Math.ScaleB() method.

C# Program

</>
Copy
using System;
 
class Example {
    static void Main(string[] args) {
        Double x;
        Int32 n;
        Double result;

        x = 3;
        n = 2;
        result = Math.ScaleB(x, n);
        Console.WriteLine($"ScaleB({x}, {n}) = {result}");

        x = 5;
        n = 4;
        result = Math.ScaleB(x, n);
        Console.WriteLine($"ScaleB({x}, {n}) = {result}");
    }
}

Output

ScaleB(3, 2) = 12
ScaleB(5, 4) = 80

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.ScaleB() method, and also learnt how to use this method with the help of C# example programs.