Tip: #27 - Convert between hex and decimal
Created: March 7, 2001 4:59 Complexity: advanced Author: vimer--AT--21cn.com Version: 6.0 Karma: 201/67 Imported from: Tip#27
when you check the output of objdump, you'll confused by the $0xFFFFFFc operand, this function translate the hexcamal to decimal.
function! Hex2Dec()
let lstr = getline(".")
let hexstr = matchstr(lstr, '0x[a-f0-9]+')
while hexstr != ""
let hexstr = hexstr + 0
exe 's#0x[a-f0-9]+#'.hexstr."#"
let lstr = substitute(lstr, '0x[a-f0-9]+', hexstr, "")
let hexstr = matchstr(lstr, '0x[a-f0-9]+')
endwhile
endfunction
usage:
5,8call Hex2Dec()
Comments
This did not work for me unless I escaped the '+' in the regular expressions. I also added handling of hexadecimal numbers with upper case letters:
function! Hex2Dec()
let lstr = getline(".") let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+') while hexstr != "" let hexstr = hexstr + 0 exe 's#0x[a-fA-F0-9]\+#'.hexstr."#" let lstr = substitute(lstr, '0x[a-fA-F0-9]\+', hexstr, "") let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+') endwhile
endfunction
o.wegner--AT--gmx.de , June 6, 2001 0:42
63 6F 6E 74 72 6F 6C
Anonymous , June 4, 2003 14:56
?control?
Anonymous , August 18, 2004 5:38
je moeder aan eht poeder
Anonymous , May 9, 2005 6:25
JOUW moeder aan MIJN poeder zul je bedoelen
blaataap--AT--hotmail.com , May 26, 2005 4:30