Core Function Oct
From Sputnik Wiki
Oct( <string> )
Contents |
Description
Converts an octal string into the numerical corresponding value.
An octal number is preceded by a 0 and contains digits from 0 to 7 only. By calling the oct() function, there are two particular cases here – the expression will be interpreted as a hexadecimal string if begins wit 0x and as a binary string if it begins with 0b.
If you want to convert numbers in or from a binary, octal or hexadecimal format you need to write them as literals, otherwise no automatic conversion will take place.
Parameters
string
The string to use.
Return Value
Octal numerical corresponding value of the input string.
Remarks
None.
Example
print oct(77), "\n"; # it prints 63 print oct('77'), "\n"; # it prints 63 print oct('077'), "\n"; # it prints 63 print oct(077), "\n"; # it prints 51 # because 077 is an octal number, first it will # be converted to a decimal number, i.e. 63 and next # oct(63) means 51 print oct('2382'), "\n"; # it prints 19 # this statement will work but it will ignore non octals # because 8 is not a digit in the octal base; however, # the rest of digits starting with 8 will be ignored and the oct # function will convert the octal number 23 in decimal print oct('0x77'), "\n"; # it prints 119 # ' 0x77' is considered the hexadecimal number 77; # converted in decimal this means 119; # the leading spaces are ignored print oct('0b101'), "\n"; # it prints 5 # '0b101' is considered the binary number 101; # converted in decimal this means 5