#### Topic: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

I welcome, such task, is a line with the color description in 16-richnoj to the form, we tell "0xFFAABB", there is a structure of type RGB with three fields of type unsigned char r/g/b. It is necessary for me  this line and to write down in structure each color component in the customary form, . from 0 to 255. , there is a type variant:

``````RGB (int hexValue) {
_r = ((hexValue&gt;&gt; 16) AND 0xFF) / 255.0;//Extract the RR byte
_g = ((hexValue&gt;&gt; 8) AND 0xFF) / 255.0;//Extract the GG byte
_b = ((hexValue) AND 0xFF) / 255.0;//Extract the BB byte``````

But here integer, and at me a line, I will not drive how to arrive, can prompt? (

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

I dont know wrote:

But here integer, and at me a line, I will not drive how to arrive

Unless to transform a line in whole with the help, for example, atoi - not the axiomatic decision?.

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

Dimitry Sibiryakov;
Not, atoi returns 0. I rummage on forums, a campaign, it is necessary to transform at first to any intermediate form, or in parts to transform.

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

I dont know wrote:

there is a line with the color description in 16-richnoj to the form

What in line?

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

Isokerf;
Line of such type "0xFFFFFF" It was played even with function strtoul (), it returns correct value if it to transfer a line without "0x", but while translating in RGB (on the code resulted above), in RGB units, instead of numerical value 255 register only.
Likely I will process beforehand this line - to cut "0x", remaining to transfer in strtoul (), remains  how to make so that in structure RGB fields value 0-255 registered, instead of is simple 0-1.

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

If to translate or write a translator from 16-richnoj it is difficult, simply make the parcer.
Each color two discharges, tear out on two letters from a line and consider

``````int color (char r1, char r0) {
return hex (r1) * 16 + hex (r0);
}
int hex (char x) {
if (x&gt; = ' 0 ' && x &lt;= ' 9 ') {
return x - ' 0 ';
} else if (x&gt; = ' A ' && x &lt;= ' F ') {
return x - ' A ' + 10;
} else {
return 0;
}
}``````

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

I dont know;

``sscanf_s ("0xFFAABB", "%x", &r);``
I dont know wrote:

remains  how to make so that in structure RGB fields value 0-255 registered, instead of is simple 0-1.

I do not understand. Did not put on 255.0 and the range will be 0. 255

#### Re: There is a line with color of a type 0xFFAABB how to result it in normal type RGB?

wrote:

did not put on 255.0 and the range will be 0. 255

Too so thought already, to a campaign and I will arrive.
[quote =] sscanf_s

Not . Tomorrow with it I will try. Or as offered Dima T   "parcer"
P.S. If does not complicate, explain, what for to subtract the character:

``````int hex (char x) {
if (x&gt; = ' 0 ' && x &lt;= ' 9 ') {
return x - ' 0 ';//what for here it
} else if (x&gt; = ' A ' && x &lt;= ' F ') {
return x - ' A ' + 10;//or it
} else {
return 0;
}
}``````

I remember, somewhere met an explanation, but him I will not recall (