© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
Barvier

❔ Converting String to an integer with a Hexadecimal Value

Hello Folks,

I got a process with a prefered imagebase equal to 002E0000.
I would like to store that value assigned to an integer since its a hexadecimal value which can be stored as it.
What is more I would like the value to be have a prefix "0x" so in full format the integer should look like this

public static int PROCESSBASEADRESS_INT = 0x002E0000
public static int PROCESSBASEADRESS_INT = 0x002E0000

I have a following code that gets the value from process and saves it as an integer however here is my issues:
- it does not store it in hexadecimal value
- I need it stored as an hexadecimal integer value with pre-fix "0x"

            Process process = Process.GetProcessesByName(testprocess)[0];
            ProcessModule mainModule = process.MainModule;
            int baseAddressInt = int.Parse(mainModule.BaseAddress.ToString("X"), NumberStyles.HexNumber);
            PROCESSBASEADRESS_INT = baseAddressInt;
            Console.WriteLine(PROCESSBASEADRESS_INT);
            Process process = Process.GetProcessesByName(testprocess)[0];
            ProcessModule mainModule = process.MainModule;
            int baseAddressInt = int.Parse(mainModule.BaseAddress.ToString("X"), NumberStyles.HexNumber);
            PROCESSBASEADRESS_INT = baseAddressInt;
            Console.WriteLine(PROCESSBASEADRESS_INT);


It prints it out as a INT32 value.
I need to print out hexadecimal value with a prefix "0x"

I tried converting it to string and adding "0x" but after that I cant convert it back to hexadecimal integer that represent exactly what string was showing.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Converting from binary to integer
C#CC# / help
3y ago
✅ Converting string to DateTimeOffset
C#CC# / help
2y ago