![]() |
| ||
| converting bool[8] to char hey..I need to convert a 8 value bool array to char.How can I do this? |
| ||
| Re: converting bool[8] to char You can use the bool array as a "bit-position" array for the representation of a char.
Edit: I'm not near a compiler, so the bit-shifting operator may need to be switched but the logic is straightfoward. Hopefully this helps! =) -Alex |
| ||
| Re: converting bool[8] to char I had char boolsToChar(bool* bools){but clearly this is not as nice a solution as above, For multiple reasons. One being that I get a warning for converting a double to a char and two I have a conditional statment that i clearly don't require Anyhow the solution above compiled for me, but I needed to change it around a little to come up with 'A'. bool bits[] = {1, 0, 0, 0, 0, 0, 1, 0}; |
| ||
| Re: converting bool[8] to char Hmm, try changing char to unsigned (if it exists @_@ ) -Alex Edit: I am really tired #_# I didn't realize I made the array back-asswards XD XP |
| ||
| Re: converting bool[8] to char How about this, rather unusual method ;) #include <iostream>Theres practically no maths involved :) |
| ||
| Re: converting bool[8] to char Thanks a lot! :D |
| All times are GMT -4. The time now is 6:07 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC