extern crate hex;
fn main()
{
let blue: u32 = hex::decode("0c1047"); // Error over here
}
So I want blue to store #0c1047 this hexadecimal value inside blue (here is the color picker site https://duckduckgo.com/?q=color+picker&t=hk&ia=answer. Is there a way to directly store hexadecimal values or do I have to store it in a decoded fashion or something.
Additonally to store an rgb value I have to declare u32 bits of memory, am I correct?
0x0c1047 is just a way of writing a number. Computers store them in a binary format anyway, so your options are to store it as a hex-string (not a number) or parse it into 3 u8 numbers and store them.
let hex = "0c1047";
let r = u8::from_str_radix(&hex[0..2], 16).unwrap();
let g = u8::from_str_radix(&hex[2..4], 16).unwrap();
let b = u8::from_str_radix(&hex[4..6], 16).unwrap();
let color = (r, g, b);