Computing.Net > Forums > Programming > or in C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

or in C

Reply to Message Icon

Name: WantToKnow
Date: September 5, 2002 at 03:14:22 Pacific
OS: linux
CPU/Ram: 320
Comment:

hi,

i have a c program as below. Does anybody know why the output c and d always equals to 1, even the parameter of or have different values ?

well, what i know to do is:
eg. num = 10100001 01011010 (short num)
c = 0 (unsigned char c)

num or c => 01011010 (the last 8 bits of num)

c is declared unsigned char, because i need to to store this value into an array of char (char len[2]). And num needs to be 2 bytes long, therefore i declare it as type short.

#include
#include

void or(short num)
{
unsigned char c = 0;
short d = 0 ;

c = num || c;
d = num || d;

printf("c = num || c : %d \n", c);
printf("d = num || d : %d \n", d);


return;
}


int main(void)
{
or(259);

return 0;
}

thanks a lot!! thanx

WantToKnow



Sponsored Link
Ads by Google

Response Number 1
Name: chris holt
Date: September 5, 2002 at 03:42:51 Pacific
Reply:

I suspect your confusing a logical or '||' with a bitwise or '|'.


0

Response Number 2
Name: WantToKnow
Date: September 5, 2002 at 04:01:57 Pacific
Reply:

it works!!! thanks Chris Holt. you help me a lot !!



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


C Reference Like php.net Visual C++



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: or in C

Help in C Prog www.computing.net/answers/programming/help-in-c-prog/891.html

What must I know to do this in C++? www.computing.net/answers/programming/what-must-i-know-to-do-this-in-c/4516.html

Get processors clock in C/C++ or VB www.computing.net/answers/programming/get-processors-clock-in-cc-or-vb/1160.html