Converting integer to binary string is a very simple matter. for this there is a special class call "bitset".
so fallow the example bellow and try to play around "bitset"
For more information visit http://www.cplusplus.com/reference/stl/bitset/
so fallow the example bellow and try to play around "bitset"
For more information visit http://www.cplusplus.com/reference/stl/bitset/
#include <iostream> #include <bitset> void main(){ //creating instance using bitset (16 bit). here you can specify the length suc as 8,16,32,64... std::bitset< 16 > btFlaged; //assigning integer values to instance btFlaged = 1234; //print bit string in the string for(int i =0; i< btFlaged.size(); i++){ std::cout <<btFlaged.test(i) << std::endl; } }
Finally a good/understandable/simple explanation i was looking for...
ReplyDeletec++ language example codes to beginners
ReplyDeletecplusplus code | Returns a const iterator pointing to the first element