hey..I need to convert a 8 value bool array to char.How can I do this?
AutoC
0
Junior Poster in Training
Recommended Answers
Jump to PostYou can use the bool array as a "bit-position" array for the representation of a char.
#include <iostream> using std::cout; using std::cin; using std::endl; int main(){ bool bits[] = {0, 1, 0, 0, 0, 0, 0, 1}; char c = 0; for(int i = 0; i < …
Jump to PostI had
char boolsToChar(bool* bools){ char c = 0; for( int i = 0; i < 8; i++ ) if( bools[i] ) c += pow(2,i); return c; }
but clearly this is not as nice a solution as above, For multiple reasons.
One being that I …
All 5 Replies
Alex Edwards
321
Posting Shark
Paul.Esson
53
Junior Poster
Alex Edwards
321
Posting Shark
William Hemsworth
1,339
Posting Virtuoso
AutoC
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.