Hi Jeri!

On Do, 11 Jun 2009, Jeri Raye wrote:

> Are there character based hex2bin and bin2hex functions in vim?
> Or are there scripts known that perform that functions?
> 
> I need to converted code with binairy values into hex values.
> So the line:
> 
> load s0, 01010101
> 
> needs to become
> 
> load s0, 55
> 
> Or are there S&R commands that can do that?

Well, first I thought, this would work:
::%s/[01]\+$/\=printf("%0X",str2nr(submatch(0),2))
but unfortunately str2nr only understands base 8,10 and 16. So I used 
bc as external command to take care of the binary conversion:

:%s/[01]\+$/\=printf("%X",system('echo "ibase=2; '.submatch(0).'"|bc'))


regards,
Christian
-- 
:wq!

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to