So I have a char array in C…for example:
uchar arr[3] = { 0x34, 0x45, 0xFF }
I am looking for a fast way to add an integer to it (like its 0x3445FF) so for example if I add 2 to arr I get:
{ 0x34, 0x46, 0x01 }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The easiest and best way will be to convert to int, add, and then convert back. Also, you need to decide on the byte-order since it’s never clear.
This code assumes big-endian, i.e. the array initially holds the number 0x3445ff: