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);
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.
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)
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.
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.
from what i remembered they are something like int or unsigned int.
Please try to use this one.....
unsigned long long
unsigned long int
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