Hex Number Rounder

Take a list of hex values and round each one to the nearest multiple of a rounding unit you also give as a hex value (for example 0x10 or 0x100), using standard round-half-up tie-breaking, useful for snapping addresses or sizes to an alignment boundary. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

Rounding to a fixed boundary, like the nearest 0x10, 0x100, or 0x1000, comes up constantly in low-level work: memory alignment, page-size boundaries, and bucket-style grouping of values all rely on it.

This tool rounds every value in a list of hex values to the nearest multiple of a rounding unit you specify (also as a hex value), using standard round-half-up tie-breaking.

What Is Hex Number Rounder?

The Hex Number Rounder treats each value in your list as a number and finds the closest multiple of the rounding unit, exactly like rounding 47 to the nearest 10 gives 50 in decimal, just with hex numbers and a hex-specified unit.

The rounding unit itself is entered as hex (not decimal), since alignment boundaries in this space are almost always expressed that way, 0x10, 0x100, 0x1000, and so on.

How Hex Number Rounder Works

For each value, the tool computes its remainder when divided by the rounding unit; if that remainder is at least half the unit, the value rounds up to the next multiple, otherwise it rounds down to the previous one.

All arithmetic is done with BigInt, so this works correctly for hex values far larger than JavaScript's normal 53-bit safe integer range.

When To Use Hex Number Rounder

Use this to snap addresses, offsets, or sizes to an alignment boundary, for example rounding a set of allocation sizes up or down to the nearest 0x1000 (4 KiB) page boundary.

It's also useful for bucketing a list of hex values into coarser groups for a quick visual summary, rounding a spread of values to the nearest 0x100 to see which hundred-block each falls in.

Features

Advantages

  • Uses BigInt arithmetic throughout, so it works correctly on hex values of any size, not just ones that fit in a normal JavaScript number.
  • Standard, predictable round-half-up tie-breaking rather than an unspecified or banker's-rounding behavior.
  • The rounding unit itself is flexible: any positive hex value works, not just powers of 16.

Limitations

  • Only rounds to the nearest multiple, always up on an exact tie; there's no option for round-half-down or round-to-even behavior.
  • The rounding unit must be a valid, positive hex value; text or zero are rejected with an error rather than silently ignored.

Examples

Rounding a mixed list to the nearest 0x10

Input

1A
14
18
FF, rounding unit: 10

Output

20
10
20
100

0x1A (26) and 0x18 (24, an exact tie) both round up to 0x20 (32); 0x14 (20) rounds down to 0x10 (16); 0xFF (255) rounds up to 0x100 (256).

Rounding to the nearest 0x100

Input

150
180, rounding unit: 100

Output

100
200

0x150 (336) is closer to 0x100 (256) than 0x200 (512), so it rounds down; 0x180 (384) is exactly halfway, so it rounds up to 0x200 (512).

Best Practices & Notes

Best Practices

  • Pick a rounding unit that's a power of 16 (0x10, 0x100, 0x1000) when working with alignment or page-size boundaries, since that matches how most systems express those constraints.
  • Remember the rounding unit is hex, not decimal, entering "100" rounds to the nearest 256 (0x100), not the nearest 100.

Developer Notes

Rounding is computed as `remainder = value % unit`, then the result is `value - remainder` (round down) or `value - remainder + unit` (round up) depending on whether `remainder * 2 >= unit`, all using BigInt so it's exact for arbitrarily large hex values.

Hex Number Rounder Use Cases

  • Snapping memory addresses or allocation sizes to a page or alignment boundary
  • Bucketing a spread of hex values into coarser groups for a quick summary
  • Sanity-checking whether a value is already aligned to a given boundary (compare input to output)

Common Mistakes

  • Entering the rounding unit as a decimal number by habit; it's parsed as hex, so "100" means 256, not one hundred.
  • Expecting a tie to round down; this tool always rounds ties up, matching standard round-half-up convention.

Tips

  • If a value's output equals its input, that value was already exactly aligned to the rounding unit.
  • Use a rounding unit of "1000" (hex, i.e. 4096) to quickly check page-alignment for a list of addresses.

References

Frequently Asked Questions