Algorithm to count in binary
hi,
To get back to programming I decided to create a small program that "accounts" in binary. I am currently developing an algorithm on paper yet, but a troubling me greatly. I explain:
0001 = The block number is, we modify it to become zero and completes the lower value.
0010 = There is still a zero, it fulfills.
0011 = There is new block, it will reset everything and then fills the lower value.
0100 = There are two zeros, one meets the right-most.
0101 = The problem comes from here, how to understand it must then complete the value in this way before: 0110.
The technique I wanted to use that manipulate an array of length 4 for the moment, I can count to 15 yet.
Re: Algorithm to count in binary
I would say you, rethink your algorithm.
You could instead simply add 1 to the right completely. Then you verified cases by case. If your number is bigger than 1, you put it back to 0 and keep the rest that you added to the next box. If the box becomes larger than 1 ... and so on. By adding an operation, you could smoothly and added binary. And adding a parameter, you can add in all the basics.
Re: Algorithm to count in binary
I did not quite understand the art. If I understand this is how it works:
0001
* Verification Number *
(Not on) are added one at last
0002
* Verification Number *
* It removes the 2 and replaces it with a 0 to 1 prior to the lower value *
0010
But I still think the same block in place. You could tell me what if I'm wrong?
Re: Algorithm to count in binary
Addition in binary is a simple Boolean logic. To implement an adder (educationally) better to go through the principles of logic gates. This is what the ALU (arithmetic logic unit) of your processor.