Go Down

Topic: Help: RFID and serLCD (Read 924 times) previous topic - next topic

Nick Gammon

Code: [Select]
 if(dat >= 0x30 && dat <= 0x39)
   return (dat - 0x30);
 }else if(dat >= 0x41 && dat <= 0x46)

OK, so you are comparing an incoming digit to be in the range 0 to 9, or A to F?

And you don't think this is more readable? When it mentions 0-9 and A-F and not some hex equivalent?

Code: [Select]
 if(dat >= '0' && dat <= '9')
   return (dat - '0');
 }else if(dat >= 'A' && dat <= 'F')

Oh well, whatever works for you I guess.

I relatively, or with a bit of maths, know the value used.

With my method you don't need the maths.


You have a good point, I appreciate it and will remember for future projects, but it currently forces me to remember how to do it, as with many of my classes they still have some form of HEX, BIN and OCT conversions.

Go Up