Convert dec2hex and hex2dec number

Hi, I have DS18B20 ID's saved in EEPROM.
I write data to EEPROM from PC using my simple protocol - I send BYTE enter BYTE enter,... from pc to arduino.
Each byte is value from 0 to 255.
So if my DS18B20 has ID "28, 5D, 95, A2, 2, 0, 1, F9" i save to EEPROM "40, 93, 149, 162, 2, 0, 1, 249" - it is the same but in dec.

I have following code:

struct Abc {
  byte DS18B20ID[9];
  float tmp;
  byte relay; 
};

Abc s[3];

byte getAbcArrayID(byte* ) {
  int sensorCount=sizeof(s) / sizeof(Abc);
  
  for (int n=0; n<sensorCount ;n++) {
    for (int i=0; i<8 ;i++) {
      if (s[n].DS18B20ID[i] == soughtID[i]) {
        return n;
      }
    }
  }
}

void loop () {
	byte count = sensors.getDeviceCount();
	DeviceAddress da;
	sensors.requestTemperatures();
	if (!count == 0) {
	  for (byte i=0; i<count; i++) {
	    byte id[8];
	    for (byte e=0; e<8; e++) {        
	      sensors.getAddress(da, i);   
	      id[e] = da[e];  
	    }
	    byte XXX = getAbcArrayID(id);
	}
}

It doesn't work, because I compare "28, 5D, 95, A2, 2, 0, 1, F9" with "40, 93, 149, 162, 2, 0, 1, 249" - 5D!=95.

How can I convert dec2hex or hex2dec?
Or is there any other way how can I solve this problem?

Is possible to modify "void print_char_hex(volatile avr32_usart_t *usart, unsigned char n)"?

So if my DS18B20 has ID "28, 5D, 95, A2, 2, 0, 1, F9" i save to EEPROM "40, 93, 149, 162, 2, 0, 1, 249" - it is the same but in dec.

No, you don't. Data is stored in EEPROM in binary.

	byte count = sensors.getDeviceCount();
	DeviceAddress da;
	sensors.requestTemperatures();
	if (!count == 0) {

Get the temperatures, even if there are no sensors. Why?

It doesn't work

How do you know it doesn't work?

Where does the array of Abc objects (stupid name, by the way) get assigned values?

If you are having trouble with hex and decimal representations of numbers then write a short simple program so you can learn how to manage that problem.

Don't try to figure out that basic stuff in a program with complicated things like structs and arrays of structs.

Note that I have bolded the word "repesentations" because any number can be represented in any base system - but it is always the same number.

You have choice to store in the EEPROM the number or an ASCII version of the number - and neither approach is better than the other - it just depends on what you need the data for.

For example if you have the number byte myNum = 69; it will be stored in RAM as 0b01000101. Its hex equivalent is 0x45.
You can store the byte in the EEPROM, or you could choose to store the two characters 6 and 9 or you could choose to store the two characters 4 and 5.

You just need to decide a consistent approach and stick to it for writing to and reading from the EEPROM.

...R

PaulS:
No, you don't. Data is stored in EEPROM in binary.

Physical representation does not interest me.

PaulS:

 byte count = sensors.getDeviceCount();

DeviceAddress da;
sensors.requestTemperatures();
if (!count == 0) {



Get the temperatures, even if there are no sensors. Why?
How do you know it doesn't work?

"!count == 0" of count>0 - if there is min 1 sensor.

PaulS:
Where does the array of Abc objects (stupid name, by the way) get assigned values?

Abc is only for example. Is it problem?

Robin2:
For example if you have the number byte myNum = 69; it will be stored in RAM as 0b01000101. Its hex equivalent is 0x45.
You can store the byte in the EEPROM, or you could choose to store the two characters 6 and 9 or you could choose to store the two characters 4 and 5.

You do not understand me.

DS18B20 library read sensor ID and return me "28, 5D, 95, A2, 2, 0, 1, F9".
EEPROM.read() return to me "40, 93, 149, 162, 2, 0, 1, 249".
It is the same, but 1-wire return me HEX representation and EEPROM read DEC representation. How can I compare it?

If both is the same (HEX for example) I can use:

struct Abc {
  byte DS18B20ID[9];
  float tmp;
  byte relay; 
};

Abc s[3];

byte getAbcArrayID(byte* ) {
  int sensorCount=sizeof(s) / sizeof(Abc);
  
  for (int n=0; n<sensorCount ;n++) {
    for (int i=0; i<8 ;i++) {
      if (s[n].DS18B20ID[i] == soughtID[i]) {
        return n;
      }
    }
  }
}

If I store ID static (s[0].DS18B20ID = {0x28, 0x5D, 0x95, 0xA2, 0x2, 0x0, 0x1, 0xF9}) it works good.
But if I storred it in EEPROM and read I have this problem.

But if I storred it in EEPROM and read I have this problem.

Then you are making a mistake in the way you store and read back the numbers.

How the data gets stored, and retrieved, is entirely up to you. If you're getting ASCII digits from some device, and you want to written to another device as binary numbers, YOU have to do the conversion to make that happen. Same goes when reading back. It is up to you to know what the different formats are, and to do the necessary conversions. In most cases, EEPROM libraries simple write/read binary bytes, and neither know nor care whether those bytes are encoded as ASCII characters, signed ints, longs, floats or whatever.

Regards,
Ray L.

DS18B20 library read sensor ID and return me "28, 5D, 95, A2, 2, 0, 1, F9".

it is highly unlikely that the mysterious function returns a string like that.

EEPROM.read() return to me "40, 93, 149, 162, 2, 0, 1, 249".

If that is REALLY the case, you stored data incorrectly. Storing a string representation of data is the least efficient way to store data.

Post ALL of your code.