Namespace: convert

convert

This static class offers a grab bag of methods for various types of data conversion operations. WARNING: unless otherwise noted, any method that accepts a string input *must* be ASCII-encoded. (ie. no UTF8 / Unicode multibyte characters values are accepted) Use convert.utf8.encode to encode any non-ASCII string data as needed. Ignore this warning at your own peril.
Author:
License:
Source:

Namespaces

base64
utf8

Methods

<static> binstring_to_hex(str) → {string}

Converts an ASCII-encoded binary string to a hexadecimal string
Parameters:
Name Type Description
str string ASCII-encoded binary string
Source:
Returns:
Hexadecimal string
Type
string

<static> hex_to_binstring(hex) → {string}

Converts a hex string to an ASCII-encoded binary string.
Parameters:
Name Type Description
hex string Hexadecimal string (do not prefix with '0x'}
Source:
Returns:
ASCII-encoded binary string
Type
string

<static> to_bytes(str) → {Array}

Converts an ASCII string to an array of 8-bit integer bytes.
Parameters:
Name Type Description
str string The input string
Source:
Returns:
The byte array
Type
Array

<static> to_word(byte1, byte2, byte3, byte4) → {number}

Joins up to 4 arbitrary 8-bit integer bytes into one 32-bit integer word
Parameters:
Name Type Description
byte1 number 8-bit integer. Most significant byte
byte2 number 8-bit integer. Second most significant byte
byte3 number 8-bit integer. Third most significant byte
byte4 number 8-bit integer. Least significant byte
Source:
Returns:
A 32 bit integer word
Type
number

<static> to_words(data, options) → {Array}

Converts an ASCII string or byte array to an array of "words" (32-bit integers) (RA NOTE ~ Assumes the input string length is a multiple of 4)
Parameters:
Name Type Argument Description
data string | Array The input string or array
options Object <optional>
Optional options object.
Properties
Name Type Argument Default Description
reverse_endian boolean <optional>
false Whether to reverse the endian-ness (byte order) of the word bytes
Source:
Returns:
An array of 32-bit integers
Type
Array

<static> word_to_binstring(word) → {string}

Converts a 32-bit integer word to a 4 byte ASCII-encoded binary string
Parameters:
Name Type Description
word number 32-bit integer word
Source:
Returns:
ASCII-encoded binary string
Type
string

<static> word_to_bytes(word, Array)

Splits a 32-bit integer word to an array of four 8-bit integers
Parameters:
Name Type Description
word number 32-bit integer word
Array Array of 8-bit integers
Source:

<static> words_to_binstring(words) → {string}

Converts an array of 32-bit integer words to an ASCII-encoded binary string
Parameters:
Name Type Description
words Array Array of 32-bit integer words
Source:
Returns:
ASCII-encoded binary string
Type
string

<static> words_to_bytes(words) → {Array}

Converts an array of 32-bit integer words to an array of 8-bit integer bytes
Parameters:
Name Type Description
words Array Array of 32-bit integer words
Source:
Returns:
Array of 8-bit integer bytes
Type
Array

<static> words_to_hex(words) → {string}

Converts an array of 32-bit integer words to a hex string
Parameters:
Name Type Description
words Array Array of 32-bit integer words
Source:
Returns:
Hexademical string
Type
string