Arduino string of hex values to long converter. (useful for screens)

hey guys I just wanted to make this publicly available since I couldn’t find anyone else who has made this before.

This is a HEX to long(or string to hex) converter that takes strings as an input. I’m making a program that writes colors to a screen after reading them from an SD card so I needed this. figured someone else in the future may as well.

The screen uses hex in its display library rather then RGB so I was stuck with either converting string to hex to RGB or just string to hex and dealing with using some online converter to make my colors. I actually had no idea what hex was until after I did this so this taught me a lot about base 16 and what it is actually useful for. Feel free to use this code however you want. If you need to just steal the ConvertHex(); function feel free to and pop a string into it and it will return a value of type long!

feel free to remove all of the lines including serial commands they are just for demo use.

here is how you can test it out!
first get the code from below and upload it to an arduino of choice.
set your baud rate to 9600 and type in “HEX FFFF”
this should return the value 65535. which is represent of FFFF in hex.
as seen here

here is the code!

My main purpose in making this post is just so google shows some relevant results when googling “arduino hex to int converter” like the noob I am. :stuck_out_tongue_winking_eye:

I know hex and int and interchangeable

No, they are not

They are in the sense that both can be respresented at hex or int. The arduino idea doesnt care if I type 1+000F the result will be 15. Same with this it just takes a string of hex and converts it to be usable.

“int” is a data type.
Hex is just a representation.
They are not in any sense interchangeable.

You can, for instance, represent an IEEE754 floating point in hex, but that doesn’t make it an “int”

Fair enough in that case. My converter only deals with hex to int conversion but I'll change my post to make it more clear.