|                             ASIC/FPGA  Design and Verification Out Source Services Run a perl script from vim on a specified text block and convert binary word to hex.
							
							This pages is another example, to many other ones discussed in 
                            this site,
							on how it is easy to start a perl script from vim to do some text manipulations.
                            
							In this case there are a few binary words that first need to be concatenated to form a single binary word.
							Next the large word is chopped to 16 bits and converted to hex.
                            
							The input format was taken from VHDL code:
                            
0111100
0111100
0111100
0111100
0111100
0111100
0111100
0111100
01111000
							
                            
							The output format was taken from specman e code:
                            
							0x7878F1E3 0xC78F1e3C
							
                            
							The output format from script looks like:
                            
0111100001111000 -> 7878
1111000111100011 -> F1E3
1100011110001111 -> C78F
0001111000111100 -> 1E3C
							
                            
							The script is shown below:
                            
#!/bin/perl
$buf="";
while (<STDIN>) {
  chomp($_);
  $buf=$_ . $buf;
}#while
#convert to hex and print
$l=length($buf);
if($l > 16) {
  $j=0;
  for($i = 0; $i < $l; $i += 16) {
    $b=substr($buf, $i, 16);
    $hex = sprintf('%X', oct("0b$b"));
    print("$b -> $hex\n");
    $j++;
  }
} else {
  $hex = sprintf('%X', oct("0b$buf"));
  print("$buf -> $hex\n");
}
							
                            
                            You may find this page interesting if you have to 
                            enumerate a large number of VHDL constants: 
                             vhdl enumerate perl script
                             
                         
                         
                         
                          |  |  
                           |  |  
                              
Also available on this project:  
                              
 
 
 
 |  |