Java tutorial
//package com.java2s; public class Main { public static final int RED_SHIFT = 16; public static final int LED_INTENSITY_LEVEL_COUNT = 4; public static int color2LedRed(int color) { int red = (color >> RED_SHIFT) & 0xFF; int newRed = (int) Math.round(red * (LED_INTENSITY_LEVEL_COUNT - 1) / (double) 0xFF); return newRed; } }