HEX to ASCII converter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • SUF6NEWBIE

    HEX to ASCII converter

    Well..when there is a need - 'make it happen 'Capin'

    this stuff wil convert a HEX string to ASCII standard character output.
    There is know doubt some pure LUA code for this, I could not find any..

    Code:
    -- Functions to convert Hex data(string) to ASCII
    
    
    -- read the 'ASCII.TXT' to a table - at say 'on startup' actions
    
    G_HX_CONV_T = TextFile.ReadToTable(_SourceFolder.."\\AutoPlay\\Docs\\ASCII.TXT");
    
    
    --SOHEXGET
    function HEXGET()
    
    MainWork_str = "";
    		
    		--strHex = "whatever"; --eg: returned string from say a 'target registry read'
    			--good example is reading the Os 'dos devices' hex strings
    			--HKLM\SYSTEM\MountedDevices\ --read the values to a table and cycle through						
    		
    		--restructure returned Hex string for correct ASCII converion		
    		strHex = String.Replace(strHex, " ", ",", false); --replace all " " with ","
    		strHex = String.Replace(strHex, "00,", "", false); --now remove all "00,"
    		strHex = String.Replace(strHex, ",", "", false); --now remove all ","
    		hxlength = String.ToNumber(String.Length(strHex));		
    		hxmidstr = String.Mid(strHex, 1, 2);
    							
    		while (hxlength > 0) do
    		HEXASCII(); -- call the ASCII converter	
    		--reset for next hex find		
    		hxmidstr = String.Mid(strHex, 1, 2);
    		hxlength = String.ToNumber(String.Length(strHex)); --for loop
    			if (hxlength == 0) then
    			strASCII = MainWork_str; -- the final converted string
    			Dialog.Message("Hex-ASCII: Debug Info only", strASCII); 			
    			break; --all done
    			end											
    		end --while	
    		
    end
    --EOHEXGET
    
    --SOHexcovert
    function HEXASCII()
    
    
    	for valindex, valline in G_HX_CONV_T do
    		--reset vars
    		Decval = nil;
    		ascichar = nil;
    		hxvalname = nil;
    		hxvalname = String.Find(valline, hxmidstr.."=", 1, true);
    		if (hxvalname == 1) then
    		hxvalpos = String.Find(valline, "=", 1, false);
    		Decval = String.TrimRight(String.Mid(valline, hxvalpos +1, -1), nil);
    		ascichar = String.Char(Decval);			
    		MainWork_str = String.Concat(MainWork_str, ascichar);	
    		strHex = String.Mid(strHex, 3, -1); --remove converted from string for next
    		break;
    		end				
    	end--loop
    
    end
    --EOHexcovert
    download the file below I constructed (contains Hex-Dec - first 127 chars)
    and include in your 'source folder'.

    Is someone has something else - could ya offer it up--thanks
    Attached Files
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    #2
    There is a function in LUA string.format where you can use a %x or %X option to convert to hex and -c to convert to the char value.

    see here

    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment

    • SUF6NEWBIE

      #3
      Very cool .. tks TJ

      (i could'nt see the wood for the trees)

      Comment

      Working...
      X