 convert/bytes - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Conversion : convert/bytes

convert/bytes

convert between strings and lists of integers

 Calling Sequence convert(expr, bytes)

Parameters

 expr - string, symbol, list of integers, or floating point value

Description

 • convert, with second argument 'bytes', converts a string first argument into list of integers giving the byte values of the characters within the string.
 • If the first argument is a symbol (i.e. a simple name) and that symbol has not been assigned a value, it is treated as if it were a string.
 • Passing a list of integers as the first argument will produce a string consisting of the characters corresponding to the integers in the list. If the list contains a zero value, the string is truncated at that point.
 • A hardware floating point first argument is converted to a list of values corresponding to the 8-byte internal IEEE representation of the value.
 • A software floating point value is first converted to hardware floating point, and then converted to a list as described above.

Examples

 > $\mathrm{convert}\left("Test string",'\mathrm{bytes}'\right)$
 $\left[{84}{,}{101}{,}{115}{,}{116}{,}{32}{,}{115}{,}{116}{,}{114}{,}{105}{,}{110}{,}{103}\right]$ (1)
 > $\mathrm{convert}\left(\left[65,66,67\right],'\mathrm{bytes}'\right)$
 ${"ABC"}$ (2)

An integer outside the range 1..255 appearing in the list truncates the conversion to a string at that point.

 > $\mathrm{convert}\left(\left[65,66,0,67\right],'\mathrm{bytes}'\right)$
 ${"AB"}$ (3)
 > $\mathrm{convert}\left(\left[77,97,112,108,101,0,49,48\right],'\mathrm{bytes}'\right)$
 ${"Maple"}$ (4)
 > $\mathrm{convert}\left(1.23,\mathrm{bytes}\right)$
 $\left[{63}{,}{243}{,}{174}{,}{20}{,}{122}{,}{225}{,}{71}{,}{174}\right]$ (5)
 > $\mathrm{convert}\left(\mathrm{HFloat}\left(-\mathrm{\infty }\right),\mathrm{bytes}\right)$
 $\left[{255}{,}{240}{,}{0}{,}{0}{,}{0}{,}{0}{,}{0}{,}{0}\right]$ (6)