EDIT: What I was looking for is “string, pad left” and my question has been answered by u/d10k6
So, I’m taking a computer architecture class, and I don’t have a background in programming. I do, however, have to write code for this class that simulates a “batcher-banyan” network, which chooses the path data takes based upon its binary values..
I’ve got the logic worked out on paper, and I’ve managed to call methods from my main (WOOHOO!)
My issue is with conversion. I have generated an array of random numbers, and managed to convert them to binary strings.
I am using Convert.ToString(inputNum[i], 2)
If position “i” in my array holds the value of 5 as an integer, my converted string is “101”
I would like it to print out as “000101” instead.
My integer values range from 0 – 31, so I can’t simply concatenate a fixed amount of 0’s at the beginning.
Is what I want possible? I don’t know anyone who programs C#, and this isn’t exactly a question that I can find an answer to on StackOverflow (perhaps because I don’t know how to word it).
Have a look at String.PadLeft
I appreciate that, thank you very much.
Here is my output. The values change with each run, and I would like to make the binary printout on the right the same length regardless of the value.
https://imgur.com/a/z3unfMS
For(int I = 6 – binary.length; I > 0;) { binary = “0” + binary; }
C# devs
null reference exceptions