Jump to content

Hex to Decimal of AutoIt is Different with C#


Recommended Posts

Posted (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 by Colduction
Aded little more detail
Link to post
Share on other sites
  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
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 :D

Link to post
Share on other sites
  • Colduction changed the title to Hex to Decimal of AutoIt is Different with C#

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jmor
      For some reason, I can't convert to Hex a Decimal color that has been calculated.
      For example, this works:
      Local $iColor = 3310546 ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF) giving the expected output:
      $iColor (dec): 3310546, $iColor (hex): 3283D2
      But if I want to take an average of several colors, I have a problem.  For example this doesn't work:
      $iColor = (3310546 + 3310546) / 2 ConsoleWrite("$iColor (dec): " & $iColor & ", $iColor (hex): " & Hex($iColor, 6) & @CRLF) giving the wrong output:
      $iColor (dec): 3310546, $iColor (hex): 000000
      I observe this behavior after any processing of a decimal color.
      Is this a bug?
    • By Divane
      Hello everyone. I need to convert any string to 3-digit decimal. It is possible to convert through online tools. Is there any way to do this in AutoIt.

      For Example ;
      8cdb3 = DECIMAL 056 099 100 098 051

      Is it possible the conversion above by AutoIt? Thanks.
    • By ScrapeYourself
      I didn't like the search time of Simple Native Image Search, and being on windows 10 64bit, I couldn't get ImageSearchDll.dll to work properly.
      So I started researching image search routines and found this excellent post and set of replies find-a-bitmap-within-another-bitmap.

      I really liked the pattern that the Simple Native Image Search used, the clipboard usage and the method of searching. Although I think it could be improved by using some short circuit techniques to return sooner, like consecutive matched > 65% return | matched total > 85% return) , and I wanted the function to manage the click on the found image as well.
      So I just did a bit more research and a few trips to MSDN and stackoverflow, these two snippets allow me to replicate KyleJustKnows code, and click.  Another feature is that it also saves the image it captures to disk, so that if the image is not found you can check what was captured, and alternatively cut out a new search image to use.
      private void PrintScreen() { keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0); keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0); } public Bitmap CaptureScreenPrtSc() { PrintScreen(); if (Clipboard.ContainsImage()) { using (Image img = Clipboard.GetImage()) { img.Save("ClipBoard.PNG", ImageFormat.Png); return new Bitmap(img); } } return default; } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetCursorPos(out MousePoint lpMousePoint); [DllImport("user32.dll")] private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); private MousePoint GetCursorPosition() { var gotPoint = GetCursorPos(out MousePoint currentMousePoint); if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); } return currentMousePoint; } private void MouseEvent(MouseEvents value) { MousePoint position = GetCursorPosition(); mouse_event ((int)value, position.X, position.Y, 0, 0) ; }
      So after managing to compile the dll with COM support, with much reading of this forum and many posts from paulpmeier, ptrex, LarsJ, and others about loading .net, I managed to get this all working.

      Here is the BotIt Core:
      ; BotIt Core Global $sPath = "BotIt.dll" Global $RegAsmPath = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" Func BotIt_StartUp() RegisterBotIt() OnAutoItExitRegister("UnregisterBotIt") EndFunc ;==>BotIt_StartUp Func RegisterBotIt() RunWait($RegAsmPath & " /register /codebase /tlb " & $sPath, @ScriptDir, @SW_HIDE) EndFunc ;==>RegisterBotIt Func UnregisterBotIt() FileDelete("Step.txt") RunWait($RegAsmPath & " /unregister " & $sPath, @ScriptDir, @SW_HIDE) EndFunc ;==>UnregisterBotIt Func ActivateAndSearch($sTitle, $sImgPath, $bClick = True) WinActivate($sTitle) Sleep(1000) $oBotIt = ObjCreate("BotIt.DetectImageAndClick") ConsoleWrite($sImgPath & @CRLF & $bClick & @CRLF) $bRet = $oBotIt.FindAndClick($sImgPath, $bClick) Return $bRet EndFunc ;==>ActivateAndSearch  
      Usage:
      Do Sleep(500) Until ActivateAndSearch("Window Title", "PathToFile")

      I hope you enjoy!
      Regards,
      ScrapeYourself
       
       
      BotIt.cs
    • By DiegoCorradini
      Hi all,
      I have a problem to handle the controls of an application.
      Using AutoIT Windows Tool I can get only the Window (see Summary of the picture).
      Any tips to get the controls without knowing the name?
      (PS Using TestStack.White everything works, however I want the HIDE application feature of AutoIT). 
       
      Many thanks

    • By badcoder123
      Hey, all.  
      I've been looking for a way to change cursor colour but not the cursor itself. I've been looking for a couple hours now and can't find anything.  I also don't even know where to start, if anyone has any tips or examples please comment them.
      Thanks
×
×
  • Create New...