Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# Is there any Datatype To Store the Hexadecimal Value?

Tags:

c#

In C#

I want to Check the value which is in 8 bit Binary format (i.e. 0000000a or 00010ef0) is between the specific range....

for example (following is C language code )

int temp=5;
if (temp>=0 || temp<10)
    printf("temp is between 0-10");

same way i want to check Hexadecimal value is in Given rage or not ....

like image 441
Jitendra Avatar asked Jan 14 '12 07:01

Jitendra


People also ask

What does << mean in C?

<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .

What does %d do in C?

%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.

What is && operator in C?

The && (logical AND) operator indicates whether both operands are true. If both operands have nonzero values, the result has the value 1 . Otherwise, the result has the value 0 . The type of the result is int . Both operands must have an arithmetic or pointer type.


2 Answers

You can convert the string of the hex value to an integer

int hexvalue = int.Parse(value.ToString(),System.Globalization.NumberStyles.HexNumber);

and then do your normal test

if (hexvalue >=0 || hexvalue <10)
    Console.WriteLine("hexvalue is between 0-10");
like image 142
kamui Avatar answered Nov 15 '22 13:11

kamui


You may use int family types:

int val=0x19;
like image 42
KV Prajapati Avatar answered Nov 15 '22 14:11

KV Prajapati