Variable in Hexadecimal Format in C#

  

1
Rozpoczęcie tematu

Help me to declare an integer variable and assign it with the value 254 in hexadecimal format (0x##).

I need to print the variable and ensure that the result is “254”. Meaning the output must be the number 254.

2 Odpowiedzi
1

First you need to use Windows calculator (use the programmer option) to find 254's hexadecimal representation, which is: FE

It will look like 0xFE in hexadecimal format.

then comes the code:

using System;
 
class VariableInHexadecimalFormat
{
    static void Main()
    {
        int a = 0xFE;
        Console.WriteLine(a);
    }
}
1

Or you can convert it in the placeholder:

Console.WriteLine("{0:D}",0xFE);
Udostępnij: