Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mathf.NextPowerOfTwo

static function NextPowerOfTwo(value: int): int;
static int NextPowerOfTwo(int value);
static def NextPowerOfTwo(value as int) as int

Description

Returns the next power of two value.

	// prints 8
	Debug.Log(Mathf.NextPowerOfTwo(7));
	
	// prints 256
	Debug.Log(Mathf.NextPowerOfTwo(139));
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        Debug.Log(Mathf.NextPowerOfTwo(7));
        Debug.Log(Mathf.NextPowerOfTwo(139));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		Debug.Log(Mathf.NextPowerOfTwo(7))
		Debug.Log(Mathf.NextPowerOfTwo(139))