Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How can I get Single byte from 'int' type variable? Can we
alter single bit or multiple bits in int type variable? if so,
How?

Answers were Sorted based on User's Feedback



How can I get Single byte from 'int' type variable? Can we alter single bit or multiple b..

Answer / hassan noureddine

Use bit wise unary commands:

int i = 0x5678
char LowByte = (char) i; // yield 8;

To alter the bits

i &= 0xFF; // reset upper 2 bytes
i ^= 0xFFFF // invert all bits

Is This Answer Correct ?    0 Yes 0 No

How can I get Single byte from 'int' type variable? Can we alter single bit or multiple b..

Answer / vignesh1988i

we know that integer allocates 2 bytes of memory.
to get a single byte we must type cast the integer to character using pointers.

why because,when we take int i=10;,the binary representation for 10 is 1010 or in 8 bits it can be 0000 1010.
so in memory 2 bytes will be allocated as the whole for int.

let us consider: binary 10 address (2bytes)
0000 65534
0010 65535

in the memory according to the bytes prority the binary numbers will get stored.
so , our task is to take only one byte from int.

int i=10,*j;
j=&i;
printf('%d\n",(char*)j); // type casting of ptr varables

now. in the above ex. and according to the preceeded coding it will print 0 as the output ,which is the output from only one byte of memory location (65534).

any corrections , pl. notify me


thank u

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Interview Questions

Write a program to give following output..... ********* **** **** *** *** ** ** * * ** ** *** *** **** **** *********

4 Answers  


how to reverse string "Hello World" by using pointers only. Without any temp var

1 Answers  


SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1

4 Answers  


What is the use of putchar function?

0 Answers  


You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?

1 Answers  


code for replace tabs with equivalent number of blanks

0 Answers   Bosch,


What is pragma in c?

0 Answers  


What is the advantage of using #define to declare a constant?

0 Answers   Agilent, ZS Associates,


what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

9 Answers  


What is wrong in this statement? scanf(“%d”,whatnumber);

0 Answers  


what is meant by the "equivalence of pointers and arrays" in C?

3 Answers   Satyam,


The file stdio.h, what does it contain?

0 Answers  


Categories