LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-10-2004, 02:28 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
bit masking?


what's wrong with below code:

int a=0; int b=1; int c=3;
int e;

e &= (a|b);
printf("%d", e);
e &=(b|c);
printf("%d", e);
============================
The output will be "00", But I expected "03"

since b|c = 3 ???
 
Old 08-10-2004, 02:41 AM   #2
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
Re: bit masking?

Quote:
Originally posted by blackzone
what's wrong with below code:

int a=0; int b=1; int c=3;
int e;

e &= (a|b);
printf("%d", e);
e &=(b|c);
printf("%d", e);
============================
The output will be "00", But I expected "03"

since b|c = 3 ???
Yes, b | c is 3 (from ...01 | ...11) but e is ...00 when you calculate
(when i compile the code, e's initial value was 0; but i also expected it to be a random value, anyway)

Code:
e &= (b|c);
So, the line above becomes;
Code:
e = e & ( ...01 | ...11 );
and

Code:
e = ...00 & ...11;
and finally

Code:
e = ...00;
So the result is true..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
masking email addresses linuxhippy Slackware 3 10-08-2005 09:55 AM
Apache IP masking? totalshredder Linux - Software 1 01-16-2005 05:08 PM
a question on Masking IP Address coolamit78 Linux - Networking 7 04-22-2004 07:01 AM
Python: Bit masking images? sienarot Programming 1 03-06-2004 02:46 PM
packet masking??? icyfire Linux - Networking 5 11-26-2002 06:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration