write a c program to change only the 3rd bit of the
particular number such that other bits are not affected..
if bitnum=10(say.. it can be any no..

Answer Posted / vadivel t

assume int holds 4bytes...

For ex:

#include <stdio.h>
int main()
{
int i = 16;
if(i & 0x04)
{
/*3rd bit is set to 1- so reset it to 0 - other bits will
not be disturbed*/
i = i & 0xFFFFFFFFB;
printf("IN IF \n");
}
else
{
/*3rd bit is set to 0- So set it to 1 - other bits will
not be disturbed*/
i = i | 0x00000004;
}
printf("%d", i);
_getch();
return 0;
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why static is used in c?

815


What is static identifier?

893


What does the error message "DGROUP exceeds 64K" mean?

972


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

853


What are the functions to open and close the file in c language?

794


Can you explain what keyboard debouncing is, and where and why we us it? please give some examples

1908


What is difference between class and structure?

815


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

968


Was 2000 a leap year?

822


any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()

903


Do array subscripts always start with zero?

991


What is the total generic pointer type?

914


write a program to generate address labels using structures?

4269


Explain what are its uses in c programming?

785


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

2830