0

How do I get the code to fill in 2d array?

I am trying to loop through all the elements in a 2d array so that all combinations of 0's and 1's for nine (9) places in each of five-hundred twelve (512) rows are represented. I then am trying to comment out the assignment lines within the function whichOne() in order to see which combination of 0's and 1's causes the assignment statements in whichOne() to yield y=19. Can you help me? Thank you! https://code.sololearn.com/clnrfk2P8lEF

10th Oct 2018, 6:53 PM
Thomas Yates
Thomas Yates - avatar
9 Antworten
+ 4
I get you want an array of 512 values filled out with the 9 bit pattern that equals the value. I don't understand what you are trying to do with the 19. Are you looking for all of the patterns that have their last 5 bits ending in 10011 (i.e. 19)? Without understanding what you want to do, I can not make it happen.
11th Oct 2018, 9:47 AM
John Wells
John Wells - avatar
+ 3
It is a hexadecimal value of 512. I use hex to show bits when I am using it as such. https://www.javamex.com/tutorials/conversion/decimal_hexadecimal.shtml
16th Oct 2018, 1:05 PM
John Wells
John Wells - avatar
+ 1
I fixed the bit pattern only. Your printout of them hits the SoloLearn timeout limit. I suggest changing the starting and ending numbers of the loop to limit the output to what works as a section. Then, rerun once for each section so you can verify the entire array. https://code.sololearn.com/cADVXhbEs9Mt
11th Oct 2018, 12:07 PM
John Wells
John Wells - avatar
+ 1
Outer loop should do 0 to 63, 64 to 127, 128 to 191, and 192 to 511. Remove it once done.
11th Oct 2018, 12:13 PM
John Wells
John Wells - avatar
+ 1
Thank you! I will try it as you suggest
11th Oct 2018, 12:14 PM
Thomas Yates
Thomas Yates - avatar
+ 1
Let me know, if you want some help on the function. Good luck!
11th Oct 2018, 12:15 PM
John Wells
John Wells - avatar
+ 1
The code shifts that single bit down one bit at a time (256, 128, 64, 32, 16, 8, 4, 2, & 1) to see if the corresponding bit is set in the number.
16th Oct 2018, 1:13 PM
John Wells
John Wells - avatar
0
Thank you. The code has statements which operate on x and y. I am trying to comment out statements such that y is finally 19. The array represents the different ways to leave in or comment out the statements. For example: 000100001 means comment out statements 1, 2, 3, 5,6,7,8 and leave in statements 4 and 9. The x=1 and y=0 initialization is not included. The statement 1 is the first statement after y=0.
11th Oct 2018, 11:07 AM
Thomas Yates
Thomas Yates - avatar
0
John, can you please point me to a good reference to understand this line: int pattern = 0x100; I am trying to understand how this is working. Thank you.
16th Oct 2018, 2:37 AM
Thomas Yates
Thomas Yates - avatar