Convert a hex serial output into a normal integer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Convert a hex serial output into a normal integer

arduino putting out a hexadecimal, want to convert into a integer....

17th Mar 2017, 7:03 PM
Nathan
5 Answers
+ 7
Just use int() int(0xffffff) = 16777215
17th Mar 2017, 8:40 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
@Nathan what is the output format then?
17th Mar 2017, 9:49 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
What I meant was the exact format of a given string. Could you write what is the output of print(data)?
18th Mar 2017, 5:54 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
my current output is this: data = str(int ser.serial_readline(), 16) because the arduino converts an int before it sends it, I need to convert it back to an int to compare the 2 sets of data
17th Mar 2017, 9:27 PM
Nathan
0
@Kuba the arduino sends a number convets to hex, and sends via usb. the script stores it as an integer, ie the numbers are not the same as script is displaying hexadecimal numbers. I would like to convert it back to an integer so I can compare notes. from what I can see is that the script reads the serial, and puts it in a string, here is the fetching code. data = str(int ser.serial_readline(), 16) so if I change the int to hex it does not communicate, what I can see is that the number becomes an integer and displayed in a string, but the current integer is set to the converted hex number, now I would like to convert it back to the original integer.
18th Mar 2017, 4:55 AM
Nathan