This substitution should do it:
:%s/0x[0-9a-fA-F]*/\=printf('%08X', str2nr(submatch(0), 16))/g
The regex 0x[0-9a-fA-F]*
is straightforward, matching hex numbers as you describe.
The replacement string uses an expression, since it starts with \=
.
The expression is printf('%08X', str2nr(expand(submatch(0)), 16))
, which starts by taking the matched text submatch(0)
, then converting it to an integer, using base 16 (str2nr(..., 16)
) and finally formatting it as an hex string of length (at least) 8, padded with zeroes, using uppercase hex digits for A-F (%08X
format string).
The :%
makes this match the whole buffer and the /g
makes it match multiple hex digits on the same line.
A buffer containing a line with these contents:
0x12345678 0xABCDF
Gets converted to:
12345678 000ABCDF
Which seems to match what you describe.