Let's say we have the following:
For x, the minimum value of 0x0000 is equivalent to 0.00000, and 0xffff is equivalent to 1.00000
Let's say I have a value of 0.6829, how would I map this to the hexadecimal value of 0x.... in Javascript?
EDIT:
The reason I need this is because I want to send a message to my Philips Hue Lights over UDP, the relevant documentation for my question is as follows, note, I am now using the XY color space instead of RGB:
Example of a stream message:
Example
{
'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
0x01, 0x00, //version 1.0
0x07, //sequence number 7
0x00, 0x00, //Reserved write 0’s
0x00, //color mode RGB
0x00, // Reserved, write 0’s
0x00, 0x00, 0x01, //light ID 1
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, //red
0x00, 0x00, 0x02, //light ID 2
0x00, 0x00, 0x00, 0x00, 0xff, 0xff //blue
}
The color space formats supported are RGB and xy+Brightness. Every individual color component has a 16 bit resolution on the API. RGB values are converted into xy+Brightness by the Hue bridge.
The x and y values supported by the lamps have a 12-bits resolution, and brightness 11 bits. This means that the 16 bit resolution on the API will be truncated.
To get the best color consistency over various types of lamps (i.e. gamuts) it is best to send xy+Brightness values, as these are hardware independent.
For xy, the minimum value of 0x0000 is equivalent to 0.00000, and 0xffff is equivalent to 1.00000
The used color space format is defined in the “Color space” byte part of the message header.
alert(0xffff * 0.6829)works fine and displays44753.8515. What do you need the end result for? If this is just about the number, the format doesn't matter since its the same amount, regardless of being expressed in hex or dec.