Version: 2018.3 (switch to 2019.1)
LanguageEnglish
  • C#

Mathf.ClosestPowerOfTwo

public static int ClosestPowerOfTwo(int value);

Description

Returns the closest power of two value.

using UnityEngine;

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

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

Did you find this page useful? Please give it a rating: