Wikia

Vim Tips Wiki

Changes: Convert numbers hex/decimal via menu

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
Line 21: Line 21:
   
 
<pre>
 
<pre>
vmenu 1.220 PopUp.&amp;nr2hex &lt;ESC&gt;:exec("!echo \\"obase=16;".@*."\\" \| bc -l -q ")&lt;CR&gt;
+
vmenu 1.220 PopUp.&nr2hex <Esc>:exec("!echo \\"obase=16;".@*."\\" \| bc -l -q ")<CR>
vmenu 1.220 PopUp.hex&amp;2nr &lt;ESC&gt;:exec("!echo \\"ibase=16;".toupper(@*)."\\" \| bc -l -q ")&lt;CR&gt;
+
vmenu 1.220 PopUp.hex&2nr <Esc>:exec("!echo \\"ibase=16;".toupper(@*)."\\" \| bc -l -q ")<CR>
 
</pre>
 
</pre>
   
Line 28: Line 28:
   
 
<pre>
 
<pre>
&lt;ESC&gt;:!bash -c " &lt;see exec(...) above plus extra escaping&gt; "&lt;CR&gt;
+
<Esc>:!bash -c " <see exec(...) above plus extra escaping> "<CR>
 
</pre>
 
</pre>
   

Revision as of 09:23, September 29, 2008

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).

UNIX:

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>

Comments

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