Back to Influxdb

hex.string() function

content/flux/v0/stdlib/contrib/bonitoo-io/hex/string.md

latest5.1 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/contrib/bonitoo-io/hex/hex.flux#L131-L131 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

hex.string() converts a Flux basic type to a hexadecimal string.

The function is similar to string(), but encodes int, uint, and bytes types to hexadecimal lowercase characters.

Function type signature
js
(v: A) => string

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

v

({{< req >}}) Value to convert.

Examples

Convert integer to hexadecimal string

js
import "contrib/bonitoo-io/hex"

hex.string(v: 1234)// Returns 4d2


Convert a boolean to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: true)// Returns "true"


Convert a duration to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: 1m)// Returns "1m"


Convert a time to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: 2021-01-01T00:00:00Z)// Returns "2021-01-01T00:00:00Z"


Convert an integer to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: 1234)// Returns "4d2"


Convert a uinteger to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: uint(v: 5678))// Returns "162e"


Convert a float to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: 10.12)// Returns "10.12"


Convert bytes to a hexadecimal string value

js
import "contrib/bonitoo-io/hex"

hex.string(v: bytes(v: "Hello world!"))// Returns "48656c6c6f20776f726c6421"


Convert all values in a column to hexadecimal string values

Use map() to iterate over and update all input rows. Use hex.string() to update the value of a column. The following example uses data provided by the sampledata package.

js
import "sampledata"
import "contrib/bonitoo-io/hex"

data =
    sampledata.int()
        |> map(fn: (r) => ({r with _value: r._value * 1000}))

data
    |> map(fn: (r) => ({r with _value: hex.string(v: r.foo)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag
2021-01-01T00:00:00Z-2000t1
2021-01-01T00:00:10Z10000t1
2021-01-01T00:00:20Z7000t1
2021-01-01T00:00:30Z17000t1
2021-01-01T00:00:40Z15000t1
2021-01-01T00:00:50Z4000t1
_time_value*tag
2021-01-01T00:00:00Z19000t2
2021-01-01T00:00:10Z4000t2
2021-01-01T00:00:20Z-3000t2
2021-01-01T00:00:30Z19000t2
2021-01-01T00:00:40Z13000t2
2021-01-01T00:00:50Z1000t2

Output data

_time_value*tag
2021-01-01T00:00:00Zt1
2021-01-01T00:00:10Zt1
2021-01-01T00:00:20Zt1
2021-01-01T00:00:30Zt1
2021-01-01T00:00:40Zt1
2021-01-01T00:00:50Zt1
_time_value*tag
2021-01-01T00:00:00Zt2
2021-01-01T00:00:10Zt2
2021-01-01T00:00:20Zt2
2021-01-01T00:00:30Zt2
2021-01-01T00:00:40Zt2
2021-01-01T00:00:50Zt2

{{% /expand %}} {{< /expand-wrapper >}}