Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the data type of a hex value like 0xD2691E?

I'm trying to write a method which takes in a hex value such as 0xD2691E for the purpose of returning a UIColor object.

I found this macro which I want to convert into a method, but I don't know how to specify the data type other than void *.

#define UIColorFromRGB(rgbValue) [UIColor \
       colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
       green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
       blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

  //Then use any Hex value

 self.view.backgroundColor = UIColorFromRGB(0xD2691E);  
like image 494
openfrog Avatar asked Apr 10 '13 12:04

openfrog


People also ask

What data type is a hex?

Hexadecimal notation Integers are sometimes written or entered in base 16, known as hexadecimal or just "hex". Hex uses the standard digits 0 thru 9 plus letters A thru F . When hex notation is used to enter or display an integer value in Analytica, it is always preceded with 0x , as in these examples: 0x25 = 37.

What data type is hex in Java?

Hexadecimal: Base 16, whose digits consist of the numbers 0 through 9 and the letters A through F. Binary: Base 2, whose digits consists of the numbers 0 and 1 (you can create binary literals in Java SE 7 and later)

What does U mean in hex?

It means that it is an unsigned hexadecimal constant of value 47 hex = 71 decimal. If the 'u' is omitted then it is a signed hexadecimal constant of value 47 hex.


3 Answers

What is the data type of a hex value like 0xD2691E?

According to C standard, the type of an hexadecimal constant is the first of this list in which its value can be represented:

C11 (n1570), § 6.4.4.1 Integer constants

int
unsigned int
long int
unsigned long int
long long int
unsigned long long int

Since D2691E (b16) is equal to 13789470 (b10), the type of your constant depends on your implementation.

C standard only guarantees that INT_MAX >= +32767, whereas LONG_MAX >= +2147483647.

C11 (n1570), 5.2.4.2.1 Sizes of integer types

  • INT_MAX +32767
  • LONG_MAX +2147483647

Therefore, (unsigned) long int could be a suitable choice.

like image 96
md5 Avatar answered Oct 02 '22 15:10

md5


from what i remembered they are something like int or unsigned int.

like image 41
Maurice Rodriguez Avatar answered Oct 02 '22 16:10

Maurice Rodriguez


Please try to use this one.....

    unsigned long long 
    unsigned long int
like image 42
Dharmbir Singh Avatar answered Oct 02 '22 17:10

Dharmbir Singh