Hex values and uint64_t

Hello, I am currently using the RF24 Library to communicate between several of my Arduinos. The address, called the pipe, is a 40 bit hex variable initialized as

uint64_t pipe = 0xF0F0F0F011LL;

What I am trying to do is have the slave nodes receive a new address from the master node and then change their address. For instance, if the master node sends the command to change addresses followed by the byte 174, I would like the slave nodes to change their address to

                0xF0F0F0F0AELL

How would I go about changing the decimal value 174 to the hex value AE and then setting the pipe variable equal to the desired value?

For instance, if the master node sends the command to change addresses followed by the byte 174

Lets see that code...

How would I go about changing the decimal value 174 to the hex value AE

You don't need to change anything. Decimal and hex are two ways of showing a value that is stored internally in binary.

and then setting the pipe variable equal to the desired value?

Since the pipe variable is a 8 byte value, and you want to change one byte of the value, a union (between the 8 byte value and an 8 element array of type byte) would make that easy.

You can insert that byte just like so

uint64_t pipeOld = 0xF0F0F0F011LL;
uint64_t pipeNew;
byte  targetNode = 174;

void setup() {

  pipeNew = (pipeOld & ~0xFFLL) | targetNode;

  Serial.begin(115200);
  Serial.print((unsigned long)(pipeOld >> 32), 16);
  Serial.println((unsigned long)pipeOld, 16);
  Serial.print((unsigned long)(pipeNew >> 32), 16);
  Serial.print((unsigned long)pipeNew, 16);
}
void loop() {}
1 Like

You don't have to 'change' a decimal value into a hex value. These are just two different representations of the same thing. 174 is the same ax 0xAE. (If you have a statement like: if (0xAE == 174) { beep(); }, that would beep.)

pipe = pipe & 0xFFFFFFFF00LL; // <-- this clears the lower 8 bits of 'pipe'.
pipe = pipe | received_byte; // <-- this puts the 'received_byte' into the lower 8 bits of 'pipe'.

The following 2 statements are exactly identical.
pipe = pipe | 0xAE;
pipe = pipe | 174;

If you have a statement like: if (0xAE == 174) { beep(); }, that would beep.

void beep()
{
   digitalWrite(LEDPin, !digitalRead(LEDPin));
}

No, it wouldn't. It would flash an LED.

PaulS:
No, it wouldn't. It would flash an LED.

Well .. since the function is called 'beep()' but it toggles a pin labeled 'LEDPin',
it is probably wired up to something that is neither a buzzer nor an LED.
It's only logical.

But just in case we're confusing OP: The condition would evaluate to true.
(And I imagine that the compiler will recognize this and not produce any comparison/branching code at all.)

Thank you all very much!