G+_Kyle M Posted February 1, 2014 Share Posted February 1, 2014 Just finished episodes 1 & 2! Awesome shows! I'm eagerly waiting for next weeks episode. Great show, well produced, great for beginners like myself and seems to allow more advanced programmers to learn and tinker around as well. I'm looking forward to learning mobile app associated programming like Java. Thanks Fr. Robert Ballecer, SJ, Louis Maresca, & Shannon Morse, you make it fun and entertaining and very educational, keep up the great work! Link to comment Share on other sites More sharing options...
G+_Tony Gonzalez Posted February 1, 2014 Share Posted February 1, 2014 Word Link to comment Share on other sites More sharing options...
G+_Kyle M Posted February 1, 2014 Author Share Posted February 1, 2014 I was able to do the homework assignment, but am looking for take away the extra "0's" from the output. How would I go about not printing the 0's of the process? For example: 41 will output 20, 10, 5, 2, 1 and a 0 for every place up to the 32 bit position. Also, why only 32bits? Can we do 64bits since many modern systems are running at 64bits? By just changing the (sizeof(int) * 8) to sizeof(int) * 16)? Is it a compatibility thing? Link to comment Share on other sites More sharing options...
G+_Shannon Morse Posted February 2, 2014 Share Posted February 2, 2014 Kyle M oooo that's a good question. I'm fairly new to this too so I'm gonna experiment with that and see what happens! Link to comment Share on other sites More sharing options...
G+_Kyle M Posted February 3, 2014 Author Share Posted February 3, 2014 Any luck Shannon Morse? No luck here so far :-/. Michael P thanks for the link and the info. Good stuff! Link to comment Share on other sites More sharing options...
G+_Joe C. Hecht Posted February 4, 2014 Share Posted February 4, 2014 Michael P Silly ol' Anders Hejlsberg (lead architect of C# and a debtor to me for one Danish Flag). He aliased "long" to mean System.Int64. It's confusing if you are coming or going from C/C++, where the size of a long is really not defined in stone, and might be 32 bits (or more). Caution applies here to both newbies and seasoned veterans alike, if you may someday paste the code into another, similar language. If you ever find yourself really wanting a 64 bit integer, you might want to use an in explicit __int64 (or in this case, I think it would be a System.Int64 Joe Link to comment Share on other sites More sharing options...
G+_BrightSilence Posted February 4, 2014 Share Posted February 4, 2014 Kyle M I think you got one part of your question answered. The 32-bit isn't a limitation related to the cpu architecture, but to the addressed memory size for the integer type. There are other types like a long or better a System.Int64, but you rarely need them and I wouldn't bother getting into them at this point. As for the other question. The end result does not have what we call the leading zeroes, but the results for every loop iteration does. The reason for this is that the leading zeroes are eliminated at the end of the function in the "return new string(result).TrimStart('0');" line. Specifically the ".TrimStart('0')" part of that line. Now if you look back at the first part of the episode, you remember that you are done when your number variable is 0. But, the while loop in this code doesn't stop until the bits variable is 0. So it keeps dividing 0 by 2 until it runs out of the 32 bits. You can try to change the condition of the while loop to number > 0, but that will give you an interesting result. In this case I believe you'll see leading spaces in your console window instead of 0. These aren't actually spaces though, the values simply aren't set. The reason for this is that the program is expecting 32 elements but you're stopping before you have calculated them all. C# will empty any variable you define, so the result will always be empty for variables you haven't used. This is called a 'low value' character. In this case you could fix the result by changing ".TrimStart('0')" to ".TrimStart('\0')". \0 represents low values. But it's bad practice to rely on that, because other, less forgiving programming languages will not empty a variable when it is defined, which means it will simply return whatever happens to be in the memory at the assigned memory address. This could really be anything. I'm sure they will get into this when they start talking about arrays. In this piece of code result is an array. It's basically a variable that contains variables. In this case it's an array of characters. 32 characters to be precise. In the loop you start at the end of this array to calculate the individual characters in the array. The alternative method doesn't calculate any of the characters before the first 1 in the array. Don't worry if this all sounds like gibberish, you'll get to the point where this is a piece of cake soon enough. Link to comment Share on other sites More sharing options...
G+_Kyle M Posted February 5, 2014 Author Share Posted February 5, 2014 Shannon Morse I posted the question on StackOverflow seen here: http://stackoverflow.com/questions/21584364/c-sharp-how-to-remove-leading-0s-from-32bit-int David Heffernan and Austin Harris both posted working answers to our problem. I'm not sure I understand all the syntax but I am sure I will learn as I pick it apart. No more 0's!!! :) Link to comment Share on other sites More sharing options...
G+_James Maxwell Posted February 26, 2014 Share Posted February 26, 2014 Just finished ep 2 and haven't worked out how to print to formula screen yet Link to comment Share on other sites More sharing options...
Recommended Posts