Changing a value in an array and converting to RGB

Hello.
I am making a project where RFID tags on 6 RFID readers will create a 6-digit HEX-code which will be converted and output through RGB.

I am converting HEX values to RGB values and print the values in serial, which works fine. E.g when I write #FFFFFF, Serial prints its respective RGB values - 255, 255, 255.

However, I want to be able to replace one of the letters in the HEX code at a time, which should change its RGB output in serial. In this example, I am attempting to replace the last letter of #FFFFFF to 3 - #FFFFF3. Serial still reads the first two values correctly, but does not convert the last value correctly.

I have read that it is better to create a new array with the new value -
instead of replacing a value and changing the array but do not really know how. Here's what I have got now:

#include <stdlib.h>
#include <string.h>

void setup() {
Serial.begin(9600);
}

char hexColor[] = "#FFFFFF";
void HEXtoRGB();

void HEXtoRGB() {
hexColor[6] = "3";

char red[5] = {0};
char green[5] = {0};
char blue[5] = {0};

red[0] = green[0] = blue[0] = '0';
red[1] = green[1] = blue[1] = 'X';

red[2] = hexColor[1];
red[3] = hexColor[2];

green[2] = hexColor[3];
green[3] = hexColor[4];

blue[2] = hexColor[5];
blue[3] = hexColor[6];

long r = strtol(red, NULL, 16);
long g = strtol(green, NULL, 16);
long b = strtol(blue, NULL, 16);

Serial.println(r);
Serial.println(g);
Serial.println(b);
Serial.println(hexColor);
}

Any sort of input would be greatly appreciated.

Thank you.

Any sort of input would be greatly appreciated.

Anonymous printing sucks. Stop doing that.

Serial.print("red string: [");
Serial.print(red);
Serial.println("]);
Serial.print("red value: ");
Serial.println(r);

takes only a few seconds longer to type, once, but yields a lot more information from then on.

No, I'm curious why you need to store the result of converting 0xFF, which has a decimal value of 255 in a long. And, why a signed long? You don't intend to have negative color values, do you?

What DOES the code you posted do?

PaulS:
Anonymous printing sucks. Stop doing that.

What is anonymous printing?

PaulS:
No, I'm curious why you need to store the result of converting 0xFF, which has a decimal value of 255 in a long. And, why a signed long? You don't intend to have negative color values, do you?

You are totally right, it makes more sense to have unsigned long. Thank you.

PaulS:
What DOES the code you posted do?

It does not -do- anything at the moment. It is being implemented in a larger setup where RFID tags will be given a value, and when a tag is read, its value will be placed in a hex-code array. This will produce a different RGB outcome as the hex-code changes. The code converts hex to RGB fine, but I am not able to replace a letter within the hex-code array and produce the correct RGB value.

but I am not able to replace a letter within the hex-code array and produce the correct RGB value.

Your code tries to do that. Where is it failing? Add more Serial.print() statements to find out where.

What is anonymous printing?

Printing a number with nothing to indicate what the number means.

What happens if you change this line:

  hexColor[6] = "3";

to this:

  hexColor[6] = '3';