'===========================================================================
' Subject: Byte to hex conversion             Date: 12-22-02 (  :  )       
'  Author: Edwin Knoppert                     Code: PBWIN,PBDLL            
'  Origin: ebknoppert@hotmail.com           Packet: PBDLL.ABC
'===========================================================================
'Byte to Hex Function
'Edwin Knoppert
'pbwin

'// Simplistic but very fast converter. 
'// Converts ascii values to 2byte hex strings 
'// Used:   PB/WIN 
'// By:     ebknoppert @ hotmail.com 
  
#Compile Exe 
  
Option Explicit 
  
Function ByteToHex( ByVal sByteBuffer As String ) As String 
  
    Dim a  As Long 
    Dim sOut    As String 
    Dim pByt    As Byte Ptr 
    Dim pStr    As String Ptr * 2 
  
    If sByteBuffer = "" Then Exit Function 
  
    '// Output buffer, twice as large as the byte buffer. 
    sOut = String$( Len( sByteBuffer ) * 2, 0 ) 
    pByt = StrPtr( sByteBuffer ) 
    pStr = StrPtr( sOut ) 
  
    For a = 1 To Len( sByteBuffer ) 
   @pStr[a-1] = Hex$( @pByt[a-1], 2 ) 
    Next a 
  
    Function = sOut 
  
End Function 
  
Function WinMain( ByVal hCurInstance  As Long, _ 
   ByVal hPrevInstance As Long, _ 
   lpszCmdLine    As Asciiz Ptr, _ 
   ByVal nCmdShow As Long ) As Long 
  
    Dim T As String 
  
    T = Chr$( 0 To 255 ) 
    MsgBox ByteToHex( T ) 
  
    Function = 1 
  
End Function 
