How can I store a hexadecimal number in a variable without it becoming a decimal?
Or do I have to store it as either a string or integer?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Integers in .NET are not stored as decimal, they are stored as binary in two’s complement representation. Both decimal and hexadecimal are just different ways of reoresenting the number in a more human-friendly way.
If you want to output a number as hexadecimal you can use the “x” or “X” format specifier with the ToString method (which output lower- and upper-case respectively) with an optional fixed number of characters specified as “n” where n is the number of characters.
Some examples of outputting an integer as hex: