Vim Tips Wiki

Convert numbers hex/decimal via menu

Revision as of 04:31, April 25, 2008 by JohnBot (Talk | contribs)

1,619pages on
this wiki
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.

Around Wikia's network

Random Wiki