Go Integer to Hex Converter
Convert a Go integer to its hexadecimal string form — the same conversion strconv.FormatInt and the %x format verb perform.

Built by
Swapnil SanghviFull-Stack Web Developer & WordPress Developer
Swapnil Sanghvi is a full-stack web and WordPress developer, UI designer, and full-time freelancer who builds and maintains Hex Calculator.
Further reading: hex — Stack Overflow
How Go Converts an Integer to Hex
The %x format verb (used with fmt.Sprintf or fmt.Printf) converts an integer to base 16 using lowercase digits, with no prefix and no padding unless you add the # flag or a width specifier. strconv.FormatInt provides the same conversion outside of formatted printing.
Where Go Integer to Hex Actually Comes Up
Logging a Computed Value in Hex
Printing a bitmask, hash fragment, or checksum in hex often makes it easier to cross-reference against documentation or another system's output.
log.Printf("checksum: %#x", checksum)
Building a Hex-Encoded Identifier String
Converting a numeric ID to a fixed-width hex string, useful for generating compact, sortable identifiers in Go services.
fmt.Sprintf("%08x", id)
Formatting a Byte or Color Value for Display
Converting a byte or packed color integer to its hex form for logging, HTTP responses, or generating a hex color string.
strconv.FormatInt(int64(color), 16)
Why Use This Calculator Instead of Doing It by Hand
- Matches the digit output of Go's %x format verb and strconv.FormatInt
- Runs entirely in your browser — nothing you type gets sent anywhere
- Saves manually converting and formatting the output
- Useful for checking expected output before writing test assertions
Limitations
- Adds a 0x prefix and uses uppercase digits — Go's %x verb returns lowercase digits with no prefix by default (use %#x for the prefix).
- Doesn't zero-pad to a fixed width — add a width to your format verb yourself if you need that.
Frequently Asked Questions
How do I convert an integer to hex in Go?
Use fmt.Sprintf("%x", value) for a formatted string, or strconv.FormatInt(value, 16) for the same result via the strconv package — both return lowercase digits with no prefix.
How do I include the 0x prefix in the output?
Use the %#x format verb instead of %x — fmt.Sprintf("%#x", 255) returns "0xff", including the prefix automatically.
How do I zero-pad the result to a fixed width?
Add a width to the format verb, like fmt.Sprintf("%08x", value), which pads to 8 digits with leading zeros.
How do I parse a hex string back into an integer in Go?
Use strconv.ParseInt(hexStr, 16, 64) — the counterpart for parsing a hex string into an int64 (adjust the bit size argument for other widths).