❔ Converting from string into hex literal

DDingus2/13/2023
I am looking for anyone who can help convert a hex string into a int hex literal. I am creating a usb program using usblibdotnet to find and connect to a device on my computer. In order to connect to the device I need the device PID and VID defined as hexedecimal intergers but how I know to retrieve them from device manager is as a string. If I try to use a simple conversion such as "Convert.ToInt32" or even "Int.Parse" it will convert the number into its literal numerical value rather than keeping it as its hexadecimal value. ex. string = "0x05E0" needs to be int = 0x05E0. Most methods I have found for converting end up making it int = 1504 which isn't wrong but it needs to stay as its literal hexadecimal value in order to work with the library and find the device.
AAngius2/13/2023
needs to be int = 0x05E0
AAngius2/13/2023
int is int
AAngius2/13/2023
There's only one representation of it
AAngius2/13/2023
0o105 === 0x45 === 0b1000101 === 69
AAngius2/13/2023
It's all the same in memory
AAngius2/13/2023
There's no "binary integer"
AAngius2/13/2023
Or a "hexadecimal integer"
AAngius2/13/2023
There's an integer
DDingus2/13/2023
When using the libusbdotnet library, in order to open the device for usb communication it asks for the vid and pid as a int but if I give it the actual interger value instead of the hex it says it is unable to open the device because it is not found. without changing any other code than just changing the values into their hex definition the method is now able to open the device. Would that mean the method in the library is recognizing them as 2 different values?
Mmtreit2/13/2023
It only makes sense if it is taking a string instead of an int.
Mmtreit2/13/2023
Once you have an int there is no concept of it being in hex or decimal, that's purely for display purposes. In memory it's 4 bytes, period.
Mmtreit2/13/2023
Imagine C# having octal literals :when:
DDingus2/13/2023
For the meantime while I try to contact the developers of the library would there be any possible way to translate the string = "0x05E0" into an int without turning it into its decimal value of 1504?
AAngius2/13/2023
int is int
AAngius2/13/2023
Image
Mmtreit2/13/2023
So they do take a string as input instead of an integer?
Mmtreit2/13/2023
Because it is literally impossible for the behavior to change if they take an int as input, no matter what representation your original string used.
Mmtreit2/13/2023
Once you convert from string to int it's the exact same four bytes in memory, period.
DDingus2/13/2023
from what the method shows and asks for is that it needs the PID and VID of a device in a integer format however defining them as decimal values will not let the device appear and only allows it to appear when I define the values in a hexadecimal value. I appreciate the help in understanding this and I will see about waiting and contacting the developers of the library.
Mmtreit2/13/2023
There is precedent for some code requiring strings to be in hex format. The .NET runtime itself does this for certain environment variables.
Mmtreit2/13/2023
But those are strings.
AAngius2/13/2023
They're the same exact value
AAngius2/13/2023
There's no way a method that works with 0x05E0 won't work with 1504
Mmtreit2/13/2023
Unless it's taking a string as input.
Mmtreit2/13/2023
Which is what it sounds like to me.
Mmtreit2/13/2023
You can specify a value without the 0x prefix for an app.config file setting, but it's not recommended. On .NET Framework 4.8+, due to a bug, a value specified without the 0x prefix is interpreted as hexadecimal, but on previous versions of .NET Framework, it's interpreted as decimal.
OOF
AAngius2/13/2023
Ah, so now we'd need to hear what's the .NET version lol
Mmtreit2/13/2023
That's specifically for the runtime reading GC-related configuration.
Mmtreit2/13/2023
It shouldn't affect anything else I think.
AAngius2/13/2023
Same in the IL btw
Image
AAccord2/14/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.