Hi
I need some mind of algorithm that can count in binary. For example, generate a four-numbered string of numbers starting like:
0001, 0010, 0011, 0100, 0101, 0110, 0111 , 1000, 1001, 1010, 1100, 1101, 1110, 1111
The length of the number is four in this case but in general I would like it to be variable. Any suggestions are welcome! Thanks|||Just write a function which converts an int to a string, where the content of the string is the binary representation of the int. That way you can just increment an int, e.g. in a for loop, and use your function to convert it to its binary representation.|||Go PHP with that. I would use Ruby and a PHP hook.
Python could eat that up fast.
Java could also.
.
.
.
.
In the beginning there was The Command Line.|||Your algorithm is going to depend greatly on what you are coding. I mean technically if you set up a loop with a variable, you are counting in binary as computers all work in binary....But say you have an array of bits
array myBinary of bits 20 long initialized to 0s.
variable idx is the reference to the array.
variable remainder will hold our remainder.
To count from 0 to 10000
idx = 0
Keep going until we have no remainder
----if myBinary[idx] is 0
--------then myBinary[idx] = 1
--------else myBinary[idx] = 0 AND remainder = 1
Once it drops out of this logic than you should have your next binary number...
This is kind of a difficult way to do things. Just about every language I can remember working in has methods to display integer values as binary. If you could tell me what you were trying to do I might be able to help you with that.|||mail to tadius_ffx@gmail.com.
I will reply you. There are two algorithm
1.Recursive
2.Generate by Directionary Order.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment