|
Sorry Luc Pattyn,
I am a little slow in answering! I like that spoon saying.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Pssst... there is no spoon.
|
|
|
|
|
You dirty bird!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
This information is well documented. Anyway, ?: is a conditional operator:
condition ? (first_expression) : (second_expression)
where the first_expression is returned when condition is true else the second_expression is returned. The condition is (value == 1). The first_expression is (b | (1 << pos)) where b is being operated on by bitwise OR with 2pos. The second_expression is (b & (1 << pos) where b is being operated on by bitwise AND with the bitwise complement of 2pos. The result type of both expressions is an integer type and needs to be casted to a byte.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
The code looks like it was written by someone who thought himself clever.
Perhaps the code would be clearer as:
public static void Replace(ref byte b, int pos, byte value)
{
byte temp = (byte) ( 1 << pos ) ;
if ( value == 1 )
{
b |= temp ;
}
else
{
b &= ~temp ;
}
}
Though that still doesn't explain the purpose of the routine, and its name.
|
|
|
|
|
PIEBALDconsult wrote: Though that still doesn't explain the purpose of the routine, and its name.
Actually, the purpose was to confuse with clever code.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I want that after the last no. I should get a fullstop and not a comma.
Pl somebody correct my code for me.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ch11Ex03yield
{
public class Primes
{
private long min;
public long max;
public Primes()
: this(2, 100)
{
}
public Primes(long i, long j)
{
if (i < 2)
{
min = 2;
}
min = i;
max = j;
}
public IEnumerator GetEnumerator()
{
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
{
bool isPrime = true;
for (long possibleFactor = 2; possibleFactor <=
(long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
{
long remainderAfterDivision = possiblePrime % possibleFactor;
if (remainderAfterDivision == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
yield return possiblePrime;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
Console.Write("{0}{1} ",i,
(i==myPrimes.max )?".":",");
Console.ReadKey();
}
}
}
|
|
|
|
|
Calculating the end is expensive but, you always know when it starts.
class Program
{
static void Main(string[] args)
{
bool isFirst = true;
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
{
if (isFirst)
{
Console.Write(i.ToString());
isFirst = false;
}
else
{
Console.Write(", {0}",i.ToString());
}
}
if (!isFirst) Console.Write(".");
Console.ReadKey();
}
}
|
|
|
|
|
humayunlalzad wrote: (i==myPrimes.max )?".":",");
I would do this one of two ways
1 - write the first prime without a comma, then write them all with a leading comma. This means not using foreach, just a for loop.
2 - write the whole thing using a string builder, then use string mashing to remove/replace the last comma before writing to the console.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Did you read my response from when you posted this earlier?
|
|
|
|
|
I didn't spot that he's asking this over and over.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I notice a bug in you constructor: public Primes(long i, long j)
when called with i < 2 min will NOT be set to 2.
Philip Painter
|
|
|
|
|
Hello all,
I am new to programming and was wandering if I should learn with out a gui first or just command line.
thanks
|
|
|
|
|
Most programmers start off learning how to manipulate console(or command line) programs. However, developing a GUI in the past has been a much more difficult and tedious process.. With the introduction of drag and drop development environments, programming windows forms has become exponentially easier. But, I'd still start off learning simple black box console programs.
(If you're referring to developing without an IDE, that's how I started. But, it's not the easy way. Command line compilers like to puke unreadable syntax errors and exceptions at you. I had college professors to help me decipher.)
-- modified at 17:50 Friday 24th August, 2007
|
|
|
|
|
If, by "with out a gui" you mean; without an IDE, I'd say, no, definitely use an IDE (Visual Studio perhaps). But starting out writing console applications with that IDE is a very good idea.
|
|
|
|
|
No, he plainly doesn't mean that. He means should he write console or GUI programs.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Naw, you gotta do the typical "Hello World" first, which would be GUI.
Definitely use a visual IDE to develop your code.
Gary
|
|
|
|
|
If you have enough time start with GUI then commandLine and then GUI forever.
|
|
|
|
|
humayunlalzad wrote: start with GUI then commandLine and then GUI forever.
Why?
And GUI forever is not valid. There are many types of program, not all require a GUI. (A windows service, for example)
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live.
Upcoming FREE developer events:
* Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ...
* Reading: SQL Bits
My website
|
|
|
|
|
Write command line programs first. If you do, you'll be streets ahead of most other people learning today, who learn by playing with the forms designer, and have big holes in their knowledge as a result.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for the answers
I will continue to use SharpDevelop since vs2005 is to much dough
ugh boring command line lol
oh well I will search for some good tutorials...
anyone like sharpdeveoplemt or vs2005 (rich folks lol)
|
|
|
|
|
|
My advice is twofold:
- download Visual Studio Express Edition, it is free and it works really well;
- buy at least one up-to-date introductory book on the programming language of your
choice, make sure the book targets Windows and if it relies on a specific IDE it better be
Visual Studio; and then work your way through the book to make sure you fully understand
the language; it will teach you the most important classes, and it will probably
show you how to do console apps first, windows apps later.
At first, don't try to figure it all out yourself, let the book be your guide !
It will be much much faster, and much more thorough at the same time.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Stick with learning just the language via the console. Learning with a GUI will distract you from learning the fundamentals. You need to crawl (console) before you walk (GUI).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks for all the input on command vs gui for noobs...
also thanks for the express edition link
much appreciated and if you have any wisdom regarding programming please share
Thanks alot
Mark Nooby programmer
|
|
|
|