473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert a HexaDecimal char array to a Char Array Or String in C

Hi Friends,
I have a serious and irritating problem, please help

mdContext->digest[i] is an unsigned char Array with hexadecimal values so


for (i = 0; i < 16; i++)
printf ("%02x", mdContext->digest[i]);

prints 900150983cd24fb0d6963f7d28e17f72

now.... I want to get this value in a char Array, i.e if I do

printf("%s",ArrayConverted);
I want to print the above string... Please help me in doing this




Things I tried

Trial-1
unsigned char in[64]=0;
int tempValue[64];


for (i = 0; i < 16; i++){
sprintf(&tempValue[i],"%02x", (unsigned char)mdContext->digest[i]);
in[i]=(unsigned char)tempValue[i];
}

printf("%s\n\n\n",in);


This prints
90593d4bd9372e77 But Original content is 900150983cd24fb0d6963f7d28e17f72


So it is skipping many characters in between... please help me converting this hexadecimal Char array in to a String
Mar 12 '11 #1
2 8989
I found the answer myself.... Finally, I did this.

char buf[33];
int j=0;
for ( i=0; i<16; i++) {
sprintf(&buf[j], "%02x",mdContext->digest[i]);
j=j+2;
}
buf[32]=0;


I suspected if the next char that is being lost is stored in the next byte... and it is true... It worked, But can any one help me understand this behavior? Thankyou
Mar 12 '11 #2
i.e Int is also 2Bytes... when it didnot work in the firstcase, why in the second? why does it take 2 Chars and not 1 int size
Mar 12 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Ying Yang | last post by:
Hi, whats the difference between: char* a = new char; char* b = new char; char c ;
11
by: Pontus F | last post by:
Hi I am learning C++ and I'm still trying to get a grip of pointers and other C/C++ concepts. I would appreciate if somebody could explain what's wrong with this code: ---begin code block--- ...
30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
3
by: Andrew | last post by:
Hi, How do I convert an array to a string ? What I did was convert a string to an array, after some manipulation, I want to pass the value back to a string. char setchecked; setchecked =...
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
34
by: Perro Flaco | last post by:
Hi! I've got this: string str1; char * str2; .... str1 = "whatever"; .... str2 = (char *)str1.c_str();
5
by: Marc | last post by:
Hello dear, I have a string and every second char is a \0. Can I somehow convert it to a normal string. Or may-be in the underlying code I am doing something wrong, choose the wrong C# type? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.