# ClosestPowerOfTwo(int)

> Returns the closest power of two value.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.3/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static int ClosestPowerOfTwo(int value)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)):&#x20;

### Returns

| Type                                                       | Description |
| ---------------------------------------------------------- | ----------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) |             |

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // prints 8
        Debug.Log(Mathf.ClosestPowerOfTwo(7));

        // prints 16
        Debug.Log(Mathf.ClosestPowerOfTwo(19));
    }
}
```
