Reference Guide > C Routines > CONVERT_BASE Function
  

CONVERT_BASE Function
Converts a base-10 integer to an arbitrary base representation.
Usage
arr = convert_base(values, newBase [,oldBase])
Input Parameters
values—A vector of positive integers to convert. If optional parameter oldBase is provided, then values should be an m × n string array representing m numbers using n bits corresponding to an oldBase representation. The ordering should be Big-Endian.
newBase—A scalar integer defining the base representation to convert values to. Must be 2 and 36 (i.e., numbers must be representable using the ordered set [0, 1, ..., 9, a, b, ..., z]
oldBase—(Optional) The current base representation of values. If not provided, assumed to be base 10.
Returned Value
arr—A 2D string array defining the newBase representation of values in Big-Endian format (the least significant bit on the right), where arr(i,*) is the newBase representation of values(i).
Keywords
Base10—(Output) A vector of integers is returned containing the base 10 representation of values.
Example 1
This example converts base-10 numbers to base 12.
x = CONVERT_BASE([2, 8, 13, 2000], 12)
INFO, x && PM, x
; PV-WAVE prints the following:
;         X  STRING    = Array(4, 4)
;         0 0 0 2
;         0 0 0 8
;         0 0 1 1
;         1 1 a 8
PM, 1*12^3 + 1*12^2 + 10*12^1 + 8*12^0
; PV-WAVE prints: 2000
Example 2
Convert base 12 numbers to base 2, and also get base 10 representation.
y = CONVERT_BASE(x, 2, 12, Base10=b10)
PM, y
; PV-WAVE prints the following:
;   0 0 0 0 0 0 0 0 0 1 0
;   0 0 0 0 0 0 0 1 0 0 0
;   0 0 0 0 0 0 0 1 1 0 1
;   1 1 1 1 1 0 1 0 0 0 0
PRINT, 2^4 + 2^6 + 2^7 + 2^8 + 2^9 + 2^10
; PV-WAVE prints: 2000 
PRINT, b10
; PV-WAVE prints: 2       8      13   2000
See Also
INTEGER_TO_HEX

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.