3.2.9. C2D(string[,length])

Returns an whole number, which is the decimal representation of
the packed string string, interpreted as a binary number. If
length (which must be a non-negative whole number) is specified,
it denotes the number of characters in string to be converted, and
string is interpreted as a two’s complement representation of a
binary number, consisting of the length rightmost characters in
string. If length is not specified, string is interpreted as an
unsigned number.

If length is larger than the length of string, string is sign-
extended on the left.  I.e. if the most significant bit of the
leftmost char of string is set, string is padded with ‘ff’x chars
at the left side. If the bit is not set, ‘00’x chars are used for
padding.

If length is too short, only the length rightmost characters in
string are considered. Note that this will not only in general
change the value of the number, but it might even change the sign.

Note that this function is very dependent on the character set
that your computer is using.

If it is not possible to express the final result as a whole
number under the current settings of NUMERIC DIGITS, an error is
reported.  The number to be returned will not be stored in the
internal representation of the built-in library, so size
restrictions on whole numbers that generally applies for built-in
functions, do not apply in this case.

     C2D(‘foo’)          –>   ‘6713199’ /*For ASCII machines */
     C2D(‘103’x)         –>   ‘259’
     C2D(‘103’x,1)  –>   ‘3’
     C2D(‘103’x,2)  –>   ‘259’
     C2D(‘0103’x,3) –>   ‘259’
     C2D(‘ffff’x,2) –>   ‘-1’
     C2D(‘ffff’x)   –>   ‘65535’
     C2D(‘ffff’x,3) –>   ‘65535’
     C2D(‘fff9’x,2) –>   ‘-6’
     C2D(‘ff80’x,2) –>   ‘-128’



PREV NEXT