+ 1
C++ Binary sequence increment
Hi everyone, I want to write a program that start from 0 and add 1 in each step for binary numbers in cpp I mean to have this output: 0,1,10,11,100,......
34 Respuestas
+ 4
Armina ,what have you tried so far ?
+ 3
I can't provide you with solution till the time I don't see any effort from your side. You must have written some kind of code or must have at least thought of doing something.
+ 3
Martin Taylor
Thank you so much🙏🏻🌷
+ 2
and write always your question with C++ ,example: “C++ Binary sequence increment ”
+ 1
Arsenic
I did write some algorithm and flowcharts but they are wrong and i dont know how to correct them. I want to use exclusive or to sum the number with 1 and define an array for each binary number.
a=k=a[k+1]
while(a%10>=0)
{
d=a%10 ^ 1 ^ a[k+1]
if(d==1)
a[k]=d
else
{
a[k]=0
a[k+1]=1
}
a= reverse a[k]
}
I know this code is wrong , can you elp me with the correct one?
+ 1
i will try to help you, but i’m not strong in binary operations
+ 1
#include <iostream>
#include <bitset>
#include <climits>
using namespace std;
int main() {
int i = 0b000001;
for(int j =0; j< 10; j++)
std::cout << (std::bitset<sizeof(i <<= 1) * CHAR_BIT>(i <<= 1)) << "\n";
return 0;
}
+ 1
Martin Taylor
Thanks alot, if generally i want to write the algorithm for showing these sequence, how should i write it?
l mean the algorithm and flowchart that can be used in every language not the code for specific language?
I did want to seprate each digit and with exclusive or operator to carry digit and 1 and the digit of number and store them in an array, but i had some problems with that .
Is my idea right or it is totally wrong?
Can you help to correct my algorithm please?🙏🏻
+ 1
Martin Taylor
Thanks alot for all of your explanations,
I cant thank you enough🙏🏻🌷
0
создавай сдвиг на еденицу
0
<<< 1 or <<1 or >>1))
0
Sergey
Can you please explain the whole process (algorithm or the code in c++) please?
0
sorry, no. i can’t to explain you
0
it’s need to read in google
0
or to watch code in visual studio, disassembly
0
Arsenic
I saw codes on some websites that calculate the sum of 2 n bit binary numbers, but i dont know know to write the code or even the algorithm for the binary increment
0
better write code and you give link on the your code, example so:
C# It’s a dirty code. How to do clear code? Why the test 4th fail?Это грязный код. Как сделать чистый код? Почему 4-ый тест не проходит?
https://code.sololearn.com/cVlh76Y5zg6n/?ref=app
0
or so example: C# Why the 5th tests fail?))
https://code.sololearn.com/ceEMb8AGOHo7/?ref=app
0
Sergey
Thanks for saying
Acutelly that was not a code , it was like algorithm and it has some problems, i want to understand my problems and then write the code
0
sure, but you must give link on your code here, and then we will write coment with code you here