Hex to Int Snippet

This is a hex-to-int snippet box. Type FF and copy parse/format lines for C, C++, C#, Python, JavaScript, Java, Go, Rust, PHP and AWK. int("FF", 16) is 255. JavaScript parseInt is only safe up to 2^53−1; use BigInt after that.

Examples — click a swatch

Click a value to copy it

What these snippets are

This is a hex-to-int code box, not a converter. Python int("FF", 16) is 255. JavaScript parseInt("FF", 16) is the same until the value exceeds 2^53−1, then you need BigInt("0x…"). Java Integer.parseInt turns 0xFFFFFFFF into −1; parseUnsignedInt keeps 4294967295. For the numeric conversion itself use HEX to decimal; for signed bit patterns use two's complement.

How to use it

Type hex (FF) or decimal (255). Bit width Auto / 8 / 16 / 32 / 64 pads the hex and picks C types (uint8_t … uint64_t), C# ToUInt32/64, Java int vs long, Rust u8…u64, Go ParseUint bitSize. Examples: 0xFF, 0xDEAD, 0xFFFFFFFF, 255, 0xCAFEBABE. Copy on a card copies that language; Copy result copies the hex. Identifiers stay in English on purpose.

Language traps

Always pass radix 16 — JavaScript parseInt("08") without a radix used to be octal in old engines. Python int("0xFF", 0) reads the prefix; int("FF", 0) raises. AWK snippets need gawk (or another awk with strtonum). PHP hexdec() becomes a float when the value does not fit the platform int. Values that do not fit the chosen width are rejected.

Where to use it

Paste into a gist, a workshop slide, or a review comment when someone wrote parseInt(hex) with no radix.

Questions

Why unsigned in Java?

parseInt is signed 32-bit. Patterns with bit 31 set need parseUnsignedInt or Long.parseUnsignedLong. The yellow note appears when that bit is on.

Why BigInt in JavaScript?

Number cannot represent every integer above 2^53−1. parseInt("1FFFFFFFFFFFFF", 16) will round. BigInt("0x…") does not.