multiPurpose byte - Can I get more?

Can anyone suggest any bit tricks that will get me beyond 0 to 15 for a single byte that represents 2 distinct variables? I'd like to extend beyond 16 nodeIDs.

Thanks, Dan!

// http://www.rapidtables.com/code/text/ascii-table.htm

byte nodeID = 15; // 0 to 15
byte pNum = 0;    // 0 to 15

void printByte(byte data) {
    for (byte mask = 0x80; mask; mask >>= 1) {
        Serial.print(mask&data?'1':'0');
    }
    Serial.println();
}

void setup() {
  Serial.begin(57600);
  byte testByte = (nodeID << 4) | (pNum);
  printByte(testByte);
  byte newNode = (testByte >> 4);
  byte newNum = (testByte & 0x0F);
  Serial.println(newNode);
  Serial.println(newNum);

}

void loop() {

}

.

It's not clear what you are trying to do.

A byte can store a value from 0 to 255. That's 8 bits. You can also store 2 values from 0-15 (2 4 bit numbers). You can't store more than that.

It looks like your code is trying to pack 2 4-bit (0-15) values into 1 byte, which is valid.

If you want to store more than 16 possible values in a byte, don't pack multiple things into the byte. Simply use all possible values from 0-255, and save your pNum value in a different byte.

danoduino:
Can anyone suggest any bit tricks that will get me beyond 0 to 15 for a single byte that represents 2 distinct variables? I'd like to extend beyond 16 nodeIDs.

Thanks, Dan!

// http://www.rapidtables.com/code/text/ascii-table.htm

byte nodeID = 15; // 0 to 15
byte pNum = 0;    // 0 to 15

void printByte(byte data) {
    for (byte mask = 0x80; mask; mask >>= 1) {
        Serial.print(mask&data?'1':'0');
    }
    Serial.println();
}

void setup() {
  Serial.begin(57600);
  byte testByte = (nodeID << 4) | (pNum);
  printByte(testByte);
  byte newNode = (testByte >> 4);
  byte newNum = (testByte & 0x0F);
  Serial.println(newNode);
  Serial.println(newNum);

}

void loop() {

}


.