I am trying to store a single value from an array but I must be doing something wrong because I can’t get a hex output. What am I doing wrong?
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds->read();
/*Serial.println("DS Read Data:");
Serial.println(data[i], HEX);
Serial.println(" ");*/
}
byte _dataCRC;
byte _readCRC;
Serial.print(" CRC=");
Serial.println(OneWire::crc8(data, 8), HEX); //this works prints hex value
Serial.println("Print CRC Data.");
_dataCRC = (OneWire::crc8(data, 8), HEX); //this doesn't
Serial.println(_dataCRC, HEX); //prints 10
_readCRC = (data[8], HEX);
Serial.println(_readCRC, HEX); //prints 10 as well
This is an overload of println()
that takes two parameters where the first is an arbitrary integer number and the second a constant that tells the function how to translate this into a human readable representation in hexadecimal notation.
Here you are trying to assign some "obscure" expression to a byte, but if you just do this
_dataCRC = OneWire::crc8(data, 8);
You have your byte just the way it needs to be, to be machine readable - they don't care about any human readable notation (DEC, HEX, OCT, BIN, ...)
I guess the "obscure" expression just evaluates to the last part of the list. So i'd guess HEX
is defined as 0x10

2 Likes
@LukeUSMC, HEX is a representation of a byte value, not a value format. A byte can represent a decimal value of 0-255, a hex value of 0-0xFF, an octal value of 0-377, 2’s complement of 127 to -128, etc. The byte is simply an 8-bit entity and HEX is just one way to look at it.
1 Like
Got it…corrected below. Thanks @peekay123 and @ScruffR!
_dataCRC = (OneWire::crc8(data, 8));
Serial.println(_dataCRC, HEX);
_readCRC = (data[8]);
Serial.println(_readCRC, HEX);
Now its time to go sit in a corner and worry about ending up being a Dell Employee!
1 Like
Completely different cultures between EMC and Dell…it will be an ugly clash of styles.
I see …
… always look at the bright side of life 
The bright side is my check will cash either way and no matter what I have mastered the black art of Storage Array design.
1 Like