# IDL_Integer

The IDL_Integer class contains static methods that are available for integers. In addition, because IDL_Integer is a subclass of IDL_Number, all of the IDL_Number and IDL_Variable methods are also available.

## Superclasses

IDL_Number

### IDL_Integer

- BitLength - Returns the number of bits in the current value, ignoring leading zero bits.
- BitGet - Returns the requested bit associated with the current value.
- BitSet - Returns a scalar or array of values after setting the bits on the current value.
- BitShift - Returns a scalar or array of values after shifting the bits on the current value.
- ToASCII - Converts the current number to an ASCII string.
- ToBinary - Converts the current number to a binary string.
- ToHex - Converts the current number to a hex string.
- ToOctal - Converts the current number to an octal string.

# IDL_Integer::BitLength

The IDL_Integer::BitLength method returns the number of bits in the scalar or array, ignoring any leading zero bits.

## Examples

num = [0, 1, 2, 7, 16385]

PRINT, num.BitLength( )

IDL prints:

0 1 2 3 15

## Syntax

Result = var.BitLength( )

## Return Value

A scalar byte or a byte array of the same dimensions as the variable. Each element in the Result will contain the number of bits in the corresponding value.

## Arguments

None.

## Keywords

None.

# IDL_Integer::BitGet

The IDL_Integer::BitGet method returns a byte array of the variable.

## Examples

Print the 3rd bit value of each element of an array:

num = INDGEN(8)

PRINT, num.BitGet( 3 )

IDL prints:

0 0 0 0 1 1 1 1

## Syntax

Result = var.BitGet( Location )

## Return Value

A byte array containing the bit value of each element of the variable.

## Arguments

### Location

A scalar integer designating the location of the requested bit.

## Keywords

None.

# IDL_Integer::BitSet

The IDL_Integer::BitSet method returns the variable after setting the bit or bit values.

## Examples

Print the value of a variable after setting the bits on each element:

num = [0, 0, 0, 0]

PRINT, num.BitSet([1, 2, 3, 4])

IDL prints:

1 2 4 8

## Syntax

Result = var.BitSet( Location [, /CLEAR] [, /FLIP])

## Return Value

The scalar or array of values of the variable after their bits have been set.

## Arguments

### Location

The location of which bit to set.

## Keywords

### CLEAR

Set this keyword to clear the bits specified by Location.

### FLIP

Set this keyword to flip the bits specified by Location.

# IDL_Integer::BitShift

The IDL_Integer::BitShift method returns a scalar or array after a bit shift operation.

## Examples

Print the value of a number after shifting the bit:

num = [1, 10, 100]

; [ShiftRightOnePosition, ShiftLeftFivePositions, NoShift]

PRINT, num.BitShift( [-1, 5, 0] )

PRINT, num.BitShift( [-1, 5, 0], /CIRCULAR )

IDL prints:

0 320 100

-32768 320 100

## Syntax

Result = var.BitShift( Direction [, /CIRCULAR] )

## Return Value

The value of the scalar or array after the bit shift operation.

## Arguments

### Direction

A scalar or array containing the number of bit positions and the direction of the shift.

If the element of Direction is positive, the related element of the array is left-shifted that many bit positions, with 0 bits filling vacated positions.

If the element of Direction is negative, the related element of the array is right-shifted that many bit positions, with 0 bits filling vacated positions.

## Keywords

### CIRCULAR

Set this keyword to shift the number circularly (i.e., shifting right a value of 1 would return -32768).

# IDL_Integer::ToASCII

The IDL_Integer::ToASCII method returns a string containing the ASCII value of a number.

## Examples

Print the ASCII value of a number:

num = [72, 101, 108, 108, 111]

PRINT, num.ToASCII( )

IDL prints:

Hello

## Syntax

Result = var.ToASCII( )

## Return Value

A scalar string or string array containing the ASCII values.

## Arguments

None.

## Keywords

None.

# IDL_Integer::ToBinary

The IDL_Integer::ToBinary method returns a string containing the binary representation of the number.

## Examples

Print the hex value of a number:

num = [24601, 1728, 79]

PRINT, num.ToBinary( )

IDL prints:

110000000011001 11011000000 1001111

## Syntax

Result = var.ToBinary( )

## Return Value

A scalar string or string array containing the binary representation.

## Arguments

None.

## Keywords

None.

# IDL_Integer::ToHex

The IDL_Integer::ToHex method returns a string containing the hex value of the number.

## Examples

Print the hex value of a number:

num = [24601, 1728, 79]

PRINT, num.ToHex( )

IDL prints:

6019 6C0 4F

## Syntax

Result = var.ToHex( )

## Return Value

A scalar string or string array containing the hex values.

## Arguments

None.

## Keywords

None.

# IDL_Integer::ToOctal

The IDL_Integer::ToOctal method returns a string containing the octal value of the number.

## Examples

Print the octal value of a number:

num = [24601, 1728, 79]

PRINT, num.ToOctal( )

IDL prints:

60031 3300 117

## Syntax

Result = var.ToOctal( )

## Return Value

A scalar string or string array containing the octal values.

## Arguments

None.

## Keywords

None.

## Version History

8.4 | Introduced

## See Also

Static Methods and Attributes, Variable Attributes, IDL_Number, IDL_Pointer, IDL_String, IDL_Variable