Vim Tips Wiki

Convert numbers hex/decimal via menu

1,610pages on
this wiki

Revision as of 09:23, September 29, 2008 by JohnBot (Talk | contribs)

Tip 772 Printable Monobook Previous Next

created August 18, 2004 · complexity basic · author Thomas Ramming · version 6.0

Here is a quick way to transform hex numbers to decimal or vice versa.

Visual select the number (no leading '0x' allowed, sorry) and select the menu to transform the number.

You need the calculator 'bc' (standard unix, or cygwin).


vmenu 1.220 PopUp.&nr2hex <Esc>:exec("!echo \\"obase=16;".@*."\\" \| bc -l -q ")<CR>
vmenu 1.220 PopUp.hex&2nr <Esc>:exec("!echo \\"ibase=16;".toupper(@*)."\\" \| bc -l -q ")<CR>

Windows (need something like):

<Esc>:!bash -c " <see exec(...) above plus extra escaping> "<CR>


Use script#54 to have a more general solution without using an external program like bc.

Script 54 is just a transformation of numbers, bc can really calculate, work with variables, functions etc.

So what is FAB1DF4 * FF

Just visual mark 'FAB1DF4 * FF' and select 'hex2nr' to see the result.

FAB1DF4 * FF = 67032503820
262872564 * 255 = 67032503820

Also see VimTip448.

Advertisement | Your ad here

Around Wikia's network

Random Wiki