Conversion operations between Word8.word values and characters.
Bytes are 8-bit integers as provided by the Word8 structure, but serve the dual role as elements composing the extended ASCII character set. The Byte structure provides functions for converting values between these two roles.structure Byte : BYTE
signature BYTE = sig val byteToChar : Word8.word -> char val charToByte : char -> Word8.word val bytesToString : Word8Vector.vector -> string val stringToBytes : string -> Word8Vector.vector val unpackStringVec : Word8VectorSlice.slice -> string val unpackString : Word8ArraySlice.slice -> string val packString : Word8Array.array * int * substring -> unit end
fun bytesToString bv = CharVector.tabulate( Word8Vector.length bv, fn i => byteToChar(Word8Vector.sub(bv, i))) fun stringToBytes s = Word8Vector.tabulate( String.size s,For implementations where the underlying representation of the Word8Vector.vector and string types are the same, these functions should be constant-time operations.