Search
Relevant Links
Top 10 Articles
Faster Windows 7 - How To Make Windows 7 Faster Easily And Quickly
Does your windows 7 run too slow?
Faster Windows 7 - How To Make Windows 7 Faster Easily And Quickly
Windows 7 Slow? Speed Up Slowing Windows 7 With These Tips
Windows 7 Slow? Speed Up Slowing Windows 7 With These Tips
Windows 7 Slow? Speed Up Slowing Windows 7 With These Tips
Different Types Of Computer Memory
Different Types of Computer Memory
Different Types Of Computer Memory
Successful Blogging Tips To Make Money Online
Successful Blogging Tips to Make Money Online
Successful Blogging Tips To Make Money Online
Computer Hardware - Learn How To Fix Your Computer
Computer hardware has changed a lot over the past 15 years and most computers used to be large and heavy and were very difficult to use because they did not have an operating system
Computer Hardware - Learn How To Fix Your Computer
Discount Computer Accessories
An accessory is an additional item for a product that helps in contributing to its utility
Discount Computer Accessories
Understand Viruses
Every computer user should be at least aware, if not conscious, of the now prevalent computer viruses
Understand Viruses
Evaluation Microsoft Windows 7
After the rather lackluster launch of Windows Vista, Microsoft is ready with another operating system that could succeed Windows XP in the true sense.
Evaluation Microsoft Windows 7
Satellite Tv On PC & Mobile Tv Pro
Instantly Turn your Computer into a Super TV. Does it really work?
Satellite Tv On PC & Mobile Tv Pro
Computer Firewalls
A firewall is a computer software that provides protection from hacking attempts from the Internet
Computer Firewalls
Categories
Related Links

 

ComputerInfoWeb.com

ComputerInfoWeb.com offers tips on computers, notebooks, repairs, Shopping, Software, Security, Computer Rental , Computer Shopping, Computer Programming, Computer Networking, Maintenance, Hardware, Internet, Game, Electronics and more.

Computer Algorithm

Computer Algorithm : A C Program For Obtaining A Bit From An Integer

 

/*
* getbit -- a program for obtaining a bit from an integer
*
*/
#include

/*
* the main routine -- does it all
*
* Entered by: no parameters; takes input from stdin
*
* Exits with: nothing
*
* Exceptions: bit position must be between 0 and 32"
* -- invalid bit position entered
*/
void main(void)
{
int n; /* number to get bits from */
int bpos; /* bit position we want */
register int i; /* number of numbers read */

/*
* loop reading numbers and printing bit positions
*/
while(printf("integer bitnumber> "),
(i = scanf("%d %d", n, bpos)) != -1){
/* first check the numbers input for errors */
if (i == 0){
/* nothing entered -- reprompt */
continue;
}
if (i == 1){
/* number entered -- go for bit number */
printf("bit number>> ");
/* on eof, exit */
if ((i = scanf("%d", bpos)) == -1)
exit(0);
/* if just a return, ask for number again */
if (i == 0)
continue;
}
/* is bit position too big? */
if (bpos > (sizeof(n) * 8 - 1)){
printf("bit position must be between 0 and %d\n",
sizeof(n) * 8 - 1);
continue;
}
/* print the result */
printf("%d\n", n>>bpos);
}

/*
* put out a newline, so shell prompt is on the next line
*/
putchar('\n');

/*
* fare thee well!
*/
exit(0);
}


Other Relevant Articles from this Category:
Divide And Conquer Algorithm
Bubble Sort
Quick Sort
Fibonaccian Search Algorithm
A C Program For Obtaining A Bit From An Integer
Bit Manipulation In C

More Categories:
Notebook Computer  
Computer Training  
Desktop Computer  
Computer Sale  
Computer Software  
Computer Repair  
Computer Store  
Computer Game  
Computer Hardware  
Computer Electronics  
Computer Security  
Computer Programming  
Computer Memory  
Computer Science  
Used Computer  
Computer Networking  
Computer Rental  
Computer Accessory  
Computer Algorithm  
Computer Shopping  
Computer Maintenance  
Computer Internet  
Outsourcing  
Windows 7