+ 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,......

30th Oct 2020, 9:31 AM
Armina
Armina - avatar
31 ответ
+ 4
Armina ,what have you tried so far ?
30th Oct 2020, 11:25 AM
Arsenic
Arsenic - avatar
+ 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.
30th Oct 2020, 3:02 PM
Arsenic
Arsenic - avatar
+ 3
Martin Taylor Thank you so much🙏🏻🌷
31st Oct 2020, 5:26 AM
Armina
Armina - avatar
+ 2
and write always your question with C++ ,example: “C++ Binary sequence increment ”
30th Oct 2020, 6:36 PM
Sergey
Sergey - avatar
+ 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?
30th Oct 2020, 4:38 PM
Armina
Armina - avatar
+ 1
i will try to help you, but i’m not strong in binary operations
30th Oct 2020, 6:31 PM
Sergey
Sergey - avatar
+ 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; }
30th Oct 2020, 8:21 PM
Sergey
Sergey - avatar
+ 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?🙏🏻
31st Oct 2020, 1:04 PM
Armina
Armina - avatar
+ 1
Martin Taylor Thanks alot for all of your explanations, I cant thank you enough🙏🏻🌷
31st Oct 2020, 3:00 PM
Armina
Armina - avatar
0
создавай сдвиг на еденицу
30th Oct 2020, 9:37 AM
Sergey
Sergey - avatar
0
<<< 1 or <<1 or >>1))
30th Oct 2020, 9:38 AM
Sergey
Sergey - avatar
0
Sergey Can you please explain the whole process (algorithm or the code in c++) please?
30th Oct 2020, 9:39 AM
Armina
Armina - avatar
0
sorry, no. i can’t to explain you
30th Oct 2020, 9:55 AM
Sergey
Sergey - avatar
0
it’s need to read in google
30th Oct 2020, 9:57 AM
Sergey
Sergey - avatar
0
or to watch code in visual studio, disassembly
30th Oct 2020, 10:00 AM
Sergey
Sergey - avatar
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
30th Oct 2020, 11:28 AM
Armina
Armina - avatar
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
30th Oct 2020, 5:51 PM
Sergey
Sergey - avatar
0
or so example: C# Why the 5th tests fail?)) https://code.sololearn.com/ceEMb8AGOHo7/?ref=app
30th Oct 2020, 5:59 PM
Sergey
Sergey - avatar
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
30th Oct 2020, 6:08 PM
Armina
Armina - avatar
0
sure, but you must give link on your code here, and then we will write coment with code you here
30th Oct 2020, 6:18 PM
Sergey
Sergey - avatar