Ptifou78 Posted November 4, 2011 Posted November 4, 2011 (edited) Hi all today i would like to reverse a hex string(not really reverse) I just want a function tu translate 1 CD EA 29 into 29 EA CD 01 Thanks in advance Edited November 4, 2011 by Ptifou78
JohnOne Posted November 4, 2011 Posted November 4, 2011 You can hone your logic here. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
trancexx Posted November 4, 2011 Posted November 4, 2011 Hm. This works. ConsoleWrite(_Not_Really_Reverse("1 CD EA 29") & @CRLF) Func _Not_Really_Reverse($sHex) If $sHex = "1 CD EA 29" Then Return BinaryToString("0x31204344204541203239") Return $sHex EndFunc ♡♡♡ . eMyvnE
UEZ Posted November 4, 2011 Posted November 4, 2011 (edited) Try this: ConsoleWrite(HexStringReverse("1 CD EA 29") & @LF & @error & @LF) ConsoleWrite(HexStringReverse("FF A 3 CA") & @LF & @error & @LF) ConsoleWrite(HexStringReverse("1abcdef") & @LF & @error & @LF) Func HexStringReverse($HexString, $delim= " ") ;coded by UEZ 2011 If Not IsString($HexString) Then Return SetError(1, 0, 0) ;not a string If StringRegExpReplace($HexString, "(?i)[0-9a-fs]", "") Then Return SetError(2, 0, 0) ;not a hex string Local $aResult = StringSplit($HexString, " ") If Not @error Then $aResult = StringSplit(StringRegExpReplace($HexString, "b([w])b", "0$1"), " ", 2) Else If Mod(StringLen($HexString), 2) Then $HexString = "0" & $HexString $aResult = StringRegExp($HexString, ".{2}", 3) EndIf _ArrayReverse($aResult) Return _ArrayToString($aResult, $delim) EndFunc Br, UEZ Edited November 7, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Malkey Posted November 5, 2011 Posted November 5, 2011 Here are other methods. #include<Array.au3> Local $string = "1 c8 D A" ConsoleWrite(HexReverse($string) & @LF) ; or ConsoleWrite(HexReverse1($string) & @LF) ; #include<Array.au3> required Func HexReverse($HexString) If Not String($HexString) Then Return SetError(1, 0, 0) Local $aResult = StringSplit(StringStripWS(StringRegExpReplace(StringUpper($HexString), "\b([[:xdigit:]])\b", "0\1"), 7), " ", 2) _ArrayReverse($aResult) Return _ArrayToString($aResult, " ") EndFunc ;==>HexReverse ; No includes needed Func HexReverse1($HexString) If Not String($HexString) Then Return SetError(1, 0, 0) Local $aResult $HexString = StringStripWS(StringRegExpReplace($HexString, "\b([[:xdigit:]])\b", "0\1"), 8) For $i = 1 To StringLen($HexString) Step 2 $aResult = StringMid($HexString, $i, 2) & " " & $aResult Next Return StringUpper($aResult) EndFunc ;==>HexReverse1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now