Colduction Posted May 25, 2021 Posted May 25, 2021 (edited) Hi AutoIt programmers, excuse me for bothering you with multiple topics. In AutoIt we can use Number() function to convert Hex string to number but it's output is different of C# output & and i wanna make it's output like AutoIt code. For e.g I use this in AutoIt: Local $dBinary = Binary("Hello") ; Create binary data from a string. Local $dExtract = Number(BinaryMid($dBinary, 1, 5)) ConsoleWrite($dExtract & @CRLF) And i use this for C#: using System; using System.Text; //NameSpace Is Use of Project Name namespace TEST { class Program { public static void Main(string[] args) { //declaring a variable and assigning hex value string dd = ToHex("Hello", Encoding.ASCII); decimal d = Int64.Parse(dd, System.Globalization.NumberStyles.HexNumber); Console.WriteLine("Result: " + d); //hit ENTER to exit Console.ReadLine(); } public static string ToHex(string sInput, Encoding oEncoding, bool b0x_Prefix = false) { byte[] a_binaryOutput = oEncoding.GetBytes(sInput); string sOutput = BitConverter.ToString(a_binaryOutput).Replace("-", ""); if (b0x_Prefix == false) { return sOutput; } else { return "0x" + sOutput; } } } } I say once again that excuse me for creating new topic, in fact i'm making a library for GAuthOTP from a topic in AutoIt. Edited May 25, 2021 by Colduction Aded little more detail
Moderators Melba23 Posted May 25, 2021 Moderators Posted May 25, 2021 Colduction, I believe you should be using Dec and not Number: $dBinary = Binary("Hello") ConsoleWrite($dBinary & @CRLF) $dExtract_1 = Number(BinaryMid($dBinary, 1, 5)) ConsoleWrite($dExtract_1 & @CRLF) $dExtract_2 = Dec(StringTrimLeft($dBinary, 2)) ConsoleWrite($dExtract_2 & @CRLF) ConsoleWrite("0x" & Hex($dExtract_1, 10) & @CRLF) ConsoleWrite("0x" & Hex($dExtract_2, 10) & @CRLF) As you can see, using Dec allows you to recreate the original string: 0x48656C6C6F 478560413000 310939249775 0x6F6C6C6548 0x48656C6C6F Does the Dec value match the C# output? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Colduction Posted May 25, 2021 Author Posted May 25, 2021 1 hour ago, Melba23 said: $dExtract_1 = Number(BinaryMid($dBinary, 1, 5)) ConsoleWrite($dExtract_1 & @CRLF) @Melba23 this line is what i want to tranform to C# code, but the out put of C# code is different (I've mentioned the C# code above) In fact, i'm transforming: to C#, because i think it's more optimized than other libs in Nuget, anyway i wanna do excersice
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