Tip #27: Convert hex to dec
tip karma |
Rating 208/70, Viewed by 26382
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
March 7, 2001 4:59 |
|
complexity: |
|
advanced |
author: |
|
[email protected] |
|
as of Vim: |
|
6.0 |
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()
<< Getting rid of ^M - mixing dos and unix |
add a line-number to every line without cat or awk alike utilities. >>
Additional Notes
[email protected],
June 6, 2001 0:42
|
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
|
Anonymous,
June 4, 2003 14:56
|
63 6F 6E 74 72 6F 6C
|
Anonymous,
August 18, 2004 5:38
|
?control?
|
Anonymous,
May 9, 2005 6:25
|
je moeder aan eht poeder
|
[email protected],
May 26, 2005 4:30
|
JOUW moeder aan MIJN poeder zul je bedoelen
|
|