sponsor Vim development Vim logo Vim Book Ad

ConvertBase.vim : Convert to/from various numeric bases

 script karma  Rating 30/13, Downloaded by 1937  Comments, bugs, improvements  Vim wiki

created by
Christian J. Robinson
 
script type
utility
 
description
This script is basically just three functions:
  ConvertToBase(int, base)
  ConvertFromBase(str, base)
  ConvertBases(str, base1, base2)

And two example functions that are commented out.

The following mappings may also be useful:
" Translate the character under the cursor to a decimal value:
nmap <M-a>d i<C-R>=char2nr(getline(line("."))[col(".") - 1])<CR><ESC>lx
" ... hexadecimal value:
nmap <M-a>h ix<C-R>=ConvertToBase(char2nr(getline(line("."))[col(".") - 1]),16)<CR><ESC>lx
" ... octal value:
nmap <M-a>o i<C-R>=ConvertToBase(char2nr(getline(line("."))[col(".") - 1]),8)<CR><ESC>lx
 
install details
Source the script or place it in your plugin directory.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
ConvertBase.vim 2.0 2022-08-22 9.0 Christian J. Robinson - Update for Vim 9 (no features added)
ConvertBase.vim 1.0 2001-08-06 5.7 Christian J. Robinson Initial upload
ip used for rating: 3.239.214.173

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github