c code to convert binary into hexadecimal

c code to convert binary into hexadecimal

Page 1 of 1

1 Replies - 19665 Views - Last Post: 26 June 2008 - 11:20 AM Rate Topic: -----

#1 sshivam29   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-June 08

c code to convert binary into hexadecimal

Posted 25 June 2008 - 11:23 PM

can any one correct my code to convert binary data into hexademal.I m totally confused:

/*int main()
{

char str[] = "shivam";
//char x[1000];

// Binary
for(int i = 0; i < strlen(str); ++i)
{
for(int k = 7; k >= 0; --k)
{
//for(int a=0;a<8;a++)
// x[a]=((str[i] >> k) & 1);
cout << ((str[i] >> k) & 1);
}

cout << " ";

}
cout << endl;




// Hex
cout.setf(ios::hex);
cout<< str << endl;

for (int b = 0; b < strlen(str); ++B)
cout << hex << (unsigned char) str[b];
return 0;
}

Is This A Good Question/Topic? 0
  • +

Replies To: c code to convert binary into hexadecimal

#2 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: c code to convert binary into hexadecimal

Posted 26 June 2008 - 11:20 AM

Unless you haven't noticed, the whole thing's commented. But you need to include a closing comment identifier, why do you have it like: /*int main() {? Also, please indent your code and use the code tags like this: ::code:: or better yet, replace the opening tag with code=cpp for c++
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1