Programming NXT color sensor with NXC? Currently I am working Lego robot that solves 2x2x2 Rubik's cube. I am programming Lego Mindstorms NXT 2.0 color sensor in BricxCC.

I already have RGB data with the command ReadSensorColorRaw. I heard that it is easier to get the colour from HSL format. I've tried a lot of algorithms, but none succeeded. How I can fix it to work?'

Also I heard that I need to calibrate white balance. How can I do this??
Since you are trying to solve a Rubik's cube, check out the source code for the MindCuber. The solution there is that the values are not actually converted into colors. Rather the raw values are converted to HSV and then sorted by hue. The actual value does not matter, just how close it is to the other values.

The Mindcuber also has a white calibration. This is used to identify the white values and removed them from the list before sorting which is useful since white doesn't have a meaningful hue value.