WOLFRAM SYSTEM MODELER

isPowerOf2

Determine if the integer input is a power of 2

Wolfram Language

In[1]:=
SystemModel["Modelica.Math.isPowerOf2"]
Out[1]:=

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Syntax

Math.isPowerOf2(i);

Description

The function call "Math.isPowerOf2(i)" returns true, if the Integer input i is a power of 2. Otherwise the function returns false. The Integer input has to be >=1.

Example

  Integer i1 = 1;
  Integer i2 = 4;
  Integer i3 = 9;
  Boolean result;
algorithm
  result := Math.isPowerOf2(i1);     // = true 2^0
  result := Math.isPowerOf2(i2);     // = true 2^2
  result := Math.isPowerOf2(i3);     // = false

Syntax

result = isPowerOf2(i)

Inputs (1)

i

Type: Integer

Description: Integer scalar

Outputs (1)

result

Type: Boolean

Description: = true, if integer scalar is a power of 2