(Move categories to tip template) |
(Remove html character entities) |
||
Line 15: | Line 15: | ||
<pre> |
<pre> |
||
function! Hex2Dec() |
function! Hex2Dec() |
||
− | + | let lstr = getline(".") |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+') |
let hexstr = matchstr(lstr, '0x[a-fA-F0-9]\+') |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
endfunction |
endfunction |
||
</pre> |
</pre> |
||
To convert each hex number in the range of lines 5 to 8, enter: |
To convert each hex number in the range of lines 5 to 8, enter: |
||
+ | <pre> |
||
− | |||
− | + | :5,8call Hex2Dec() |
|
+ | </pre> |
||
==Comments== |
==Comments== |
||
− | |||
− | ---- |
Revision as of 08:19, 28 September 2008
Tip 27 Printable Monobook Previous Next
created March 7, 2001 · complexity advanced · author vimer · version 6.0
Your file may contain some hexadecimal numbers (for example, "0x12ab"). You can use the following function to convert each hex number to decimal.
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
To convert each hex number in the range of lines 5 to 8, enter:
:5,8call Hex2Dec()