Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

hex

Public Function
std.fmt.hex
pub fn hex(x: anytype) [@typeInfo(@TypeOf(x)).int.bits / 4]u8

Converts an unsigned integer of any multiple of u8 to an array of lowercase hex bytes, little endian.

Params

  • x

File

fmt.zig:1333
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
pub fn hex(x: anytype) [@typeInfo(@TypeOf(x)).int.bits / 4]u8 {
    comptime assert(@typeInfo(@TypeOf(x)).int.signedness == .unsigned);
    var result: [@typeInfo(@TypeOf(x)).int.bits / 4]u8 = undefined;
    var i: usize = 0;
    while (i < result.len / 2) : (i += 1) {
        const byte: u8 = @truncate(x >> @intCast(8 * i));
        result[i * 2 + 0] = hex_charset[byte >> 4];
        result[i * 2 + 1] = hex_charset[byte & 15];
    }
    return result;
}