I want to build a color Histogram with 8 bins using data fro

I want to build a color Histogram with 8 bins using data from an image file. Each bin represents the frequency of a the RGB values.  bin1 = 128,128,128 / bin2 = 128,128,256 / bin3 = 128,256,128, ….bin8 = 256,256,256If I have RGB values {23,34,123} that would fit into bin, since all three values are between 0 and 128.  However, {23, 209, 109} would fit into bin3, and so on.  How do I use the Frequency formula to achieve this goal?