Need help putting spaces between every 4 bits

Hey, I finished most of my code I just need spaces between a group of four bits. Thanks'


#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
int value, powerof2;
char repeat = 'n';
do {
cout << "Enter a value between 0 and 65535: " << endl;
cin >> value;
if (value > 0 || value < 65535)
powerof2 = pow(2, 15);
while (powerof2 > 0) {
if (value >= powerof2) {
cout << '1';
value = value - powerof2;
}
else
cout << '0';
powerof2 = powerof2 / 2;
}
} while (repeat == 'y');
cout << "Want to run it again?" << endl;
return 0;
}
Have you tried yourself yet? If not, first do that and when you're stuck, ask for help.
To give a hint: you can use the modulo operator to put spaces every x characters. In pseudo code:
1
2
3
for char in string
    if index % 4 == 0 
        insert space
Last edited on
Topic archived. No new replies allowed.