How to convert a string to hexadecimal array in c? - hex

I need to convert an hexadecimal string to hexadecimal array. For eg:, 083ce6e3b9744adcd729ee9935158a77 is hexastring and i would like to convert this to an array and save to a variable like {0X08,0X3c,0Xe6,0Xe3,0Xb9,0X74,0X4a,0Xdc,0Xd7,0X29,0Xee,0X99,0X35,0X15,0X8a,0X77}
Is there any way to do this ?
Thanks in advance

Related

Solidity: Use String as Hex

I am new to Solidity and trying some stuff.
I would like to store the defined hex value "ac43fe" in a bytes-variable. Like this it is working fine:
bytes memory foo = hex"ac43fe";
But instead of doing it directly, I will have the hex-value inside a string. Like:
string hex = "ac43fe"
Now I am searching for a way, so that I can convert this Hex-value (stored in the string) into a bytes variable.
Thanks a lot for your help.
Best regards,
Pascal
You can convert a value to bytes by doing:
bytes <var_name> = bytes(<string_var>);
Hope this helps!

How do I convert a signed 16-bit hexadecimal to decimal?

I have a very long sequence of data stored as unsigned 16-bit PCM (it's audio). Using Frhed, I can view the file as hex. I'd like to convert the hex into decimal. So far I've exported into a csv file and attempted to convert in R using as.integer(). However, this doesn't seem to take into account that the values are signed.
You can convert hex text strings to decimal digits using strtoi. You will need to specify that the base is 16.
HexData = c("A167", "AE8F", "6A99", "0966", "784D", "A637", "102D", "4521")
strtoi(HexData, base=16L)
[1] 41319 44687 27289 2406 30797 42551 4141 17697
This is assuming unsigned data. Your question mentions both signed and unsigned so I am not quite sure which you have.

How to insert a unicode special character in QString?

I am trying to insert a special unicode character (0xFD3F) into a QString.
I tried to create QChar(0xFD3F) but when outputting this char and viewing it in a hex editor it shows 0x3F3F.
I couldn't also find a function in QString to insert a character by its hex or decimal representation.
Use QString::fromWCharArray like this:
QString::fromWCharArray(L"Hello \uFD3F Good bye")
Use QString::fromUtf8 like this:
QString::fromUtf8("Hello \uFD3F Good bye")

QString to short using toShort

I want to convert QString to short.when I try this code
ui->lineEdit->text().toShort();
It works well for text = 20 but it returns "0" for value = 20.5.
but I need value = 20. how can I solve it?
The reason that 0 is returned is because a decimal point is an invalid character for the short data type.
If you want to be able to convert floating-point numbers from QString to integers, you need to convert your text to a float or double first, then use normal rounding/truncation to convert to short.
use that convertion string:
ui->lineEdit->text()->split(".")[0].toShort(0,10);

ColdFusion: Integer "0" doesn't convert to ASCII character

I have a string (comprised of a userID and a date/time stamp), which I then encrypt using ColdFusion's Encrypt(inputString, myKey, "Blowfish/ECB/PKCS5Padding", "Hex").
In order to interface with a 3d party I have to then perform the following:
Convert each character pair within the resultant string into a HEX value.
HEX values are then represented as integers.
Resultant integers are then output as ASCII characters.
All the ASCII characters combine to form a Bytestring.
Bytestring is then converted to Base64.
Base64 is URL encoded and finally sent off (phew!)
It all works seamlessly, APART FROM when the original cfEncrypted string contains a "00".
The HEX value 00 translates as the integer (via function InputBaseN) 0 which then refuses to translate correctly into an ASCII character!
The resultant Bytestring (and therefore url string) is messed up and the 3d party is unable to decipher it.
It's worth mentioning that I do declare: <cfcontent type="text/html; charset=iso-8859-1"> at the top of the page.
Is there any way to correctly output 00 as ASCII? Could I avoid having "00" within the original encrypted string? Any help would be greatly appreciated :)
I'm pretty sure ColdFusion (and the Java underneath) use a null-terminated string type. This means that every string contains one and only one asc(0) char, which is the string terminator. If you try to insert an asc(0) into a string, CF is erroring because you are trying to create a malformed string element.
I'm not sure what the end solution is. I would play around with toBinary() and toString(), and talk to your 3rd party vendor about workarounds like sending the raw hex values or similar.
Actually there is a very easy solution. The credit card company who is processing your request needs you to convert it to lower case letters of hex. The only characters processed are :,-,0-9 do a if else and convert them manually into a string.

Resources