0

Char array into single char C++

Let’s say we have an array: unsigned char array[]={‘1’, ’5’, ‘3’} This elements are acording to ASCII 0x31, 0x35, 0x33 And i need to make a single number out of those elements 0x313533 Does anyone had any idea how can I add them like that???

1st Dec 2020, 10:52 AM
Heyy
2 Respostas
+ 2
The shortest approach I can think of is to use a stringstream, since it can automatically assume a hexadecimal base for its operations. Here is an example: https://code.sololearn.com/cQ0nMK434pqp/?ref=app Otherwise, you would probably have to do the conversion yourself, i.e. from char to decimal to hex, followed by a concatenation of the values.
2nd Dec 2020, 12:24 AM
Shadow
Shadow - avatar
0
Nice!
2nd Dec 2020, 7:59 AM
Juancho
Juancho - avatar