Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to a bool value 0 and 1 convert in long

like -0 and -1
C#
bool flag=false;

long iApplyTilde = (long) -(flag > false);


please help

thanks in advance
Posted
Comments
Herman<T>.Instance 12-Aug-11 0:15am    
false = -0 and true = -1?

It appears that you're trying to assign a tilde to a character, based upon the value of flag. Why are you going to the trouble of converting to a long? Just test the value of flag in an if statement, and act accordingly. If you must,

long lflag = 0;
if (flag) lflag=1;
long iApplyTilde = lflag;


but I see no reason for all that extra work.
 
Share this answer
 
first: -0 does noet exist

bool flag = true;
long iApplyTilde = Convert.ToInt64(flag) *-1;
Console.WriteLine(iApplyTilde);
Console.ReadKey(true);
 
Share this answer
 
It might be helpful,

C#
static void Main(string[] args)
{
    Console.WriteLine(GetLongValue(((DateTime.Now.Second % 2) == 0)));
}

private static Int64 GetLongValue(bool flag)
{
    return -Convert.ToInt64(flag);
}


Ref:
Signed_zero[^]
Floating-Point Rules [^]

:)
 
Share this answer
 
C#
bool flag = false;
long iApplyTidle = Convert.ToLong(flag);


The code above will result in iApplyTilde being = 0.

It ain't rocket surgery...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900