Skip to content

Hex converter fixes and native window - #37

Merged
iharhl merged 2 commits into
masterfrom
feature/hex-converter-fixes
Nov 17, 2026
Merged

iharhl merged 2 commits into
masterfrom
feature/hex-converter-fixes

Conversation

@iharhl

@iharhl iharhl commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Fixes wrong results in the hex converter, reworks how it is used, and moves it into its own native window.

Conversion fixes

  • Little endian is applied in both directions. Before, Dec and Bin input ignored it, so the fields disagreed (little endian Dec 13330 gave Hex 3412 and Bin 4660)
  • Signed values in little endian take the sign from the right byte (FF 00 is 255, not negative)
  • Negative numbers use the fewest bytes: -2 is FE and -128 is 80 (were FFFE and FF80). -0 is 00 instead of 16 zero bytes
  • Signed positive numbers keep a leading 00 when the top bit is set, so 200 is 00 C8 and reads back as 200
  • ASCII shows non-printable bytes as \xNN (and \ as \\) and reads them back. Before, the · placeholder was read back as UTF-8 (00 41 -> ·A -> C2 B7 41). \n, \r, \t and \0 are accepted too
  • Non-ASCII characters are an error that names their UTF-8 bytes, instead of being converted to them silently

Input

  • Converts while typing, the >> buttons are gone. Changing Endian or Signed converts the last edited field again
  • Hex accepts grouped input: DE AD BE EF, de:ad:be:ef, 0x1, 0x23 (= 01 23). Same format as hex search: a group with an odd number of digits (ABC) is ambiguous and shows a warning
  • Bin accepts a 0b prefix and groups, and keeps the byte width (0000 0001 0000 0000 is 2 bytes). Output is grouped by byte
  • - in front of Dec turns Signed on, + turns it off (and is removed)
  • Hex and Bin digits are uppercased. +, # and other symbols are dropped instead of becoming a space
  • Example placeholder in each field. The copy button is disabled for an empty field

Messages

  • Errors (red) and warnings (yellow) under the fields: invalid escape, non-ASCII character, value above 128 bits, negative value without Signed, odd hex group, more than 16 bytes for Dec. On an error the other fields are cleared instead of keeping stale values
  • Endian and Signed tooltips explain both directions with examples

Window

  • The converter is its own OS window: it can be moved outside the main window or to another monitor, and shows OS focus. Opens over the top-right corner of the main window
  • Toggle keeps it above other windows
  • Tools -> Hex Converter brings an already open converter to the front
  • The height fits the content (only the width resizes), also after zooming with Cmd +/-
  • Clicking into the converter no longer clears the byte selection

Code

  • hex_input.rs gets sanitize_hex_pattern_input for grouped hex input, plus the radix prefix and digit filters. The converter parses hex with parse_hex_pattern
  • Removed the converter focus tracking from main.rs, which is not needed with a separate window

Tests

  • Unit tests for sanitize_hex_pattern_input

Known limitations

  • Not yet run on Windows / Linux. On Wayland the window position can't be set
  • Shortcuts handled by the main window (Cmd+S, copy selection) don't work while the converter window has focus
  • Dec can't keep leading zero bytes: Hex 0001 -> Dec 1 -> Hex 01

@iharhl
iharhl force-pushed the feature/hex-converter-fixes branch from 65edc7c to 20fa375 Compare November 17, 2026 19:00
@iharhl
iharhl force-pushed the feature/hex-converter-fixes branch from 20fa375 to 3bf5775 Compare November 17, 2026 19:04
@iharhl
iharhl merged commit 0198110 into master Nov 17, 2026
9 of 10 checks passed
@iharhl
iharhl deleted the feature/hex-converter-fixes branch November 17, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant