Convert To Hex - A Procedure

Convert To Hex - Borrowed from MineSweeper5250

Problem - Convert a 4 byte binary to an eight character hex representation

Solution:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
*                                                                   *  
* ... convert 10u 0 interger into 8a hex                            *  
*                                                                   *  
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
p cvtToHex        b                                                     
d                 pi             8a                                     
d fromInt                       10u 0 Value                             
                                                                        
d $I              s              5s 0                                   
d toHex           s              8a                                     
 /free                                                                  
  For $I = 1 to 8;                                                      
     %SubSt( toHex : 9 - $I : 1 ) = hexValues( %Rem(fromInt:16) + 1 );  
     fromInt = %Div(fromInt:16);                                        
  EndFor;                                                               
  Return toHex;                                                         
 /end-free                                                              
p cvtToHex        e                                                     

                                                                                
with hexValues defined as:

d hexValues       s              1a   CtData PerRcd(16) Dim(16)     

and populated with:

**                                                  
0123456789ABCDEF



Example

fromInt = 83,613,360

toHex   = '04FBD6B0'  



Valid HTML 3.2! Creative Commons License

BrilligWare/ chris@pando.org / revised August 2006