Kristian Jude

Kristian Jude

  • NA
  • 103
  • 46.4k

Binary question.

Mar 1 2011 1:52 PM

·         Enter a do-while loop and generate a random, byte-sized, value in the range of 0 to 255. Store the random value in a variable of type byte. Display the value in hex as shown below.

·         The user will input a string containing 1's and 0's. Use a do-while loop to ensure that the length of the string is 8 characters; if it is not, honk the speaker and display an error message in yellow, and obtain new input. An invalid guess is not counted as one of the five hex values. The hex value for which an incorrect number of bit was entered will be repeated again, as shown below.

·         Convert the string to a byte-sized number. Compare the number with the random value. If the two values are the same, display a message indicating a correct result and increment the number of correct responses. If the values are different, display a message indicating that the user's response was incorrect.

·         Continue looping until the user has been presented with five hex values.

·         Display the number of correct responses.

The random byte-sized value can be generated using the random number generator. In the code shown below, the random number generator is named rndGen, and the hex value is named byHex.

byHex = (byte)rndGen.Next(256);

 

The user will input their binary value as a string of 1's and 0's. The string (sInput) can be converted to a byte by the following code:

byInput = Convert.ToByte(sInput, 2);

so far i have this.

[CODE]
            string sInput;
            Random rndGen = new Random();
            byte byhex = (byte)rndGen.Next(256);
                                 
            Console.Title = "ICA15 - Hex Quiz";
            Console.WriteLine("{0, 40}", "ICA15 - Hex Quiz");

            Console.WriteLine("\nInput the binary equivalent to the following ten hex values.");
          
            Console.Write("\nThe binary equivalent to 0x{0} is ", Convert.ToString(byhex, 16).ToUpper());
                    

            Console.WriteLine("\nPress the <Enter> key to exit:");
            Console.ReadLine();

[/CODE]


i don't know how to use the "byInput = Convert.ToByte(sInput, 2);". and how to do it in a do-while loop.


Need Help, I'm really confuse...


Answers (2)