# c code to convert binary into hexadecimal

Page 1 of 1

## 1 Replies - 19665 Views - Last Post: 26 June 2008 - 11:20 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=55926&amp;s=6eb15b09281894f8eefea7f2909ee4df&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sshivam29

• New D.I.C Head

Reputation: 0
• 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); ++
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

• D.I.C Addict

Reputation: 54
• 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: :: or better yet, replace the opening tag with code=cpp for c++
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }