0

I have an 8 bit color code in binary like so (RRRGGGBB):

00011001

I need to be able to convert it into a hex code (e.g FFFFFF). What is the best way to convert an 8 bit color code into hex?

2
  • This question belongs on stackocerflow.
    – joojaa
    Jul 26 at 5:44
  • @joojaa I did ask on stackoverflow but it got closed unfortunately
    – Packa
    Jul 26 at 5:59
1

Nobody here can decide from things presented in the question how to conversion should be made, because you gave zero info of the used coding. The bits can be for ex. indexes in a color table.

My guess:

Your bits are truncated from 8 bit rgb numbers. R and G have both 3 most significant bits left and B has only 2:

enter image description here

I inserted zeros but as well the colored bits could be selected with some other rule assuming they were truncated.

As said, this was a guess and it can be totally wrong.If you make artistic designs for a game system a programmer who works in the engine room side surely can help.

If it happens that you cannot see any connection between bits 1100 and hex number C you should start by learning binary number system and the presentation of binary numbers with hex numbers.

A little more probable guess. It maps RRRGGGBB=00000000 to hex 000000 and RRRGGGBB=11111111 to hex FFFFFF and rounds the intermediate values.

  1. Two bit BB can be 00, 01, 10 or 11. Use for them decimal blue values 0, 85, 170 and 255 or as well hex values 00, 55, AA and FF.

  2. RRR and GGG can have values 0...7 in decimal. Multiply that decimal value by 255 and divide the result by 7. Round to the nearest integer and convert to hexadecimal.

1
  • Thanks for the idea, I was going to make this in c++ so I can print out images for an operating system. I thought this was the best place where I could get an answer other than stack overflow.
    – Packa
    Jul 26 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.