I have ABC123EFFF.
I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).
I want to create a function that will accept any old string (will usually be a single word) and from that somehow generate a hexadecimal value between
#FFFFFF, so I can use it as a colour for a HTML element.
Maybe even a shorthand hex value (e.g:
#FFF) if that's less complicated. In fact, a colour from a 'web-safe' palette would be ideal.
Is there a way to convert a string (ASCII
"a-z, A-Z, 0-9") to Hex in CMake?
For example (ASCII to hex):
"HELLO" --> 0x48 0x45 0x4C 0x4C 0x4F
Should be the opposite operation of the following command (see here):
string(ASCII <number> \[<number> ...\] <output variable>)
I tried some CMake math operations, but it didn't seem to work on strings.
I can implement a function with a big "if" that compares the char input of
"a-z, A-Z, 0-9" and returns its hex according to the AsciiTable, but I am looking for a smarter/shorter solution.
Suppose I have this string
string str = "1234"
I need a function that convert this string to this string:
"0x31 0x32 0x33 0x34"
I searched online and found a lot of similar things, but not an answer to this question.
Please someone, help me to solve this challenge: I need convert string '0x0021E974' to bytes b'\x74\xe9\x21\x00'
>>> int.to_bytes(int('0x0021E974',16), 4, 'little')b't\xe9!\x00'