Im tring to do an XOR on 2 hex numbers to create a unique hex number
ex. 7F4 ^ 65D which would equal 1A9
I understand how the XOR should work but every time I try to convert the string hex number:
string hex1 = "7F4";
int hexInt = Convert.ToInt32(hex1, 16);
I end up with a number: 2036
How do I keep the integrity of the hex number so I can do an XOR on the 2 hex numbers?
A number is a number, hexadecimal is just the way the number is displayed.
7F4 hexadecimal equals 2036 decimal, and you can perform bitwise operations on it, they will produce the correct output.
Convert the hexadecimal strings to normal integers, perform the XOR on the integers and then format the resulting integer into a hexadecimal string.
string hex1 = "7F4";
string hex2 = "65D";
int dec1 = Convert.ToInt32(hex1, 16);
int dec2 = Convert.ToInt32(hex2, 16);
int result = dec1 ^ dec2;
string hexResult = result.ToString("X");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With