Converts the endianness of a value from that used by the Host to Network byte order (big-endian).


  1. Convert an integer to network byte order:

    julia> value = 123456789;
    julia> hton(value)

    This example converts the integer value from host byte order to network byte order (big-endian).

  2. Network byte order conversion for floating-point values:

    julia> fvalue = 3.14159;
    julia> hton(fvalue)

    It converts the floating-point value fvalue to network byte order.

  3. Handle negative values:
    julia> negative = -42;
    julia> hton(negative)

    Negative values are also converted to network byte order correctly.

Common mistake example:

julia> str = "Hello";
julia> hton(str)
ERROR: MethodError: no method matching hton(::String)

In this example, hton is not applicable to a string data type. It is important to note that hton is primarily used for numerical values, not for strings or other non-numeric types. Make sure to pass the appropriate data type to hton to avoid such errors.

See Also

bitpack, bitunpack, bswap, flipbits!, htol, hton, isbits, ltoh, ntoh, rol, rol!, ror, ror!, signbit,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: