-- _conv_.e
-- _conv_.e
Following global functions are defined:
converts an atom to a string according to a numerical base
Params:atom to convert
base: 2, 8, 10 or 16
length of the resulting string
base can be 2, 8, 10 or 16
resulting string length has to be specified
sequence: a formatted string
puts(1, num_to_str(10, 2, 4)) would display n in binary form: "1010"
puts(1, num_to_str(10, 8, 2)) would display n in octal form: "12"
puts(1, num_to_str(10, 10, 2)) would display n in decimal form: "10"
puts(1, num_to_str(10, 16, 2)) would display n in hexadecimal form: "0A"
str_to_num()
converts a string to an atom according to a scecified base
Params:string to convert
base: 2, 8, 10 or 16
atom
printf(1, "%d", str_to_num("1010", 2)) would display 10
printf(1, "%d", str_to_num("12", 8)) would display 10
printf(1, "%d", str_to_num("10", 10)) would display 10
printf(1, "%d", str_to_num("0A", 16)) would display 10
num_to_str(), to_number()
string to convert
uses value() but does only return converted atom
aborts in case or error
an atom
printf(1, "%d", to_number("10")) would display 10
printf(1, "%d", to_number("#0A") would display 10
printf(1, "%d", to_number("0A") would display 0
str_to_num()
converts an object in a sequence
Params:object to convert
sub-sequences appear between curly brackets as with print()
sub-sequence items are separated by commas as with print()
sequence
puts(1, to_string({{1}}&"message"&10&"and"&{{8,2},4}&233) & "\n")
{{1},109,101,115,115,97,103,101,10,97,110,100,{8,2},4,233}
num_to_str(), sequence_dump()
returns hexadecimal representation of a string
Params:string to convert
sequence
puts(1, hex_string({1,2,3,4,5,6}) & "\n")
010203040506
hex_sequence(), num_to_str()
returns hexadecimal representation of a sequence
Params:sequence to convert
sequence
puts(1, hex_sequence({1,2,3,4,5,6}) & "\n")
{#1, #2, #3, #4, #5, #6}
hex_string()
converts sequence of bytes peeked in memory to a numerical value
Params:sequence to convert
optional "direction" is NORMAL or REVERSE.
when direction is REVERSE (usual), lowest byte is first
when direction is NORMAL (telecom frames), highest byte is first
direction defaults to REVERSE.
integer
bytes_to_uint({#1C,#0A,#00,#00}, {{"direction",NORMAL}}) = #1C0A0000
bytes_to_uint({#1C,#0A,#00,#00}, {}) = #A1C
uint_to_bytes()
converts an atom to a sequence of bytes
Params:atom to convert
length of the resulting sequence
direction is NORMAL or REVERSE (default)
when direction is REVERSE (usual), lowest byte is first
when direction is NORMAL (telecom frames), highest byte is first
sequence
uint_to_bytes(#1C0A0000, 4, NORMAL) = {#1C, #0A, #00, #00}
uint_to_bytes(#1C0A0000, 4, REVERSE) = {#00, #00, #0A, #1C}
bytes_to_uint()
converts an UTF-8 char to an ASCII char
Params:UTF-8 char to convert
sequence
ascii_to_utf8()
converts an UTF-8 string to an ASCII string
Params:string to convert
sequence
ascii_to_utf8()
converts an ASCII character to its unicode equivalent
Params:integer to convert
sequence
puts(f_debug, unicode('A') & "\n") --> A
puts(f_debug, unicode(#0152) & "\n") --> Œ
puts(f_debug, unicode(#0153) & "\n") --> œ
puts(f_debug, unicode(#03C0) & "\n") --> π
utf8_to_ascii()
converts an ASCII string to an UTF-8 string
Params:string to convert
sequence
puts(f_debug, ascii_to_utf8({#0152, #0153, #03C0}) & "\n")
--> Œœπ
utf8_to_ascii()
converts a DOS character (codepage 850) to its unicode equivalent
Params:integer to convert
sequence
puts(1, cp850_to_unicode(#82) & "\n") --> #00E9 (é)
unicode_to_cp850()
converts an unicode character to its DOS equivalent (codepage 850)
Params:integer to convert
sequence
puts(f_debug, unicode_to_cp850(#00E9) & "\n") --> #82 (é)
cp850_to_unicode()
converts a DOS character (codepage 850) to its Windows equivalent (codepage 1252)
Params:integer to convert
sequence
puts(1, cp850_to_windows(#82) & "\n") --> #E9 (é)
windows_to_cp850()
converts an unicode character to its DOS equivalent (codepage 850)
Params:integer to convert
sequence
puts(f_debug, unicode_to_cp850(#00E9) & "\n") --> #82 (é)
cp850_to_unicode()
converts DOS end of lines to Unix ones
Params:string to convert
sequence
dos_to_unix("message\r\n") --> "message\n"
unix_to_dos()
converts Unix end of lines to DOS ones
Params:string to convert
sequence
dos_to_unix()