Lost Password?

  #1 (permalink)  
Old 03-18-2008, 08:34 AM
Chinmoy's Avatar   
Chinmoy Chinmoy is offline
Programming Professional
 
Join Date: Feb 2008
Location: where heaven meets earth
Posts: 301
Rep Power: 6
Chinmoy has a spectacular aura aboutChinmoy has a spectacular aura about
Default masking

in this short tutorial we see the basic use of comparing and working with data at bit level. Here we check for odd and even numbers by comparing them at the bit level.

Code:
#include<stdio.h>
#include<conio.h>
void main()
{
	int a;
           clrscr();
	printf("Enter a number to check divisibility");
	scanf("%d",&a);
	if (a&1)
	{
		printf("\nOdd");
	}
	else
		printf("\nEven");
}
Here the number we enter is checked with the binary of one at the bit level.thus any number divisible with 2 will have 0 at the first place and 1 if it is odd. The & operation returns a TRUE to the if statement if the condition is true and the number is odd else not.
Attached Thumbnails
To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.

Last edited by Chinmoy; 03-18-2008 at 11:52 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-18-2008, 10:39 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,034
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: masking

Unfortunately, your code does not work. Try entering 15.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-18-2008, 11:54 AM
Chinmoy's Avatar   
Chinmoy Chinmoy is offline
Programming Professional
 
Join Date: Feb 2008
Location: where heaven meets earth
Posts: 301
Rep Power: 6
Chinmoy has a spectacular aura aboutChinmoy has a spectacular aura about
Default Re: masking

oh i had something else in my mind!really sorry for that and thanks for pointing out..
ive edited the post.it'll work fine now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 09:15 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads