ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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?
 Question Submitted By :: Richmike
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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?
Answer
# 1
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
Hassan Noureddine
 
  Re: 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?
Answer
# 2
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 0 No
Vignesh1988i
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
how do u find out the number of 1's in the binary representation of a decimal number without converting it into binary(i mean without dividing by 2 and finding out the remainder)? three lines of c code s there it seems...can anyone help  2
Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i.e we can write this string in 120 ways for that write a program Subex3
what is c? Tech-Mahindra5
What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() { char *g="String"; myalloc(g,20); strcpy(g,"Oldstring"); printf("The string is %s",g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these IBM3
how to find a 5th bit is set in c program IBM3
fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? } NDS13
How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?  1
Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass. Microsoft6
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } ME3
How to use c/c++ code in JAVA Satyam7
how to find out the inorder successor of a node in a tree?? TCS2
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } CitiGroup4
Write code for atoi(x) where x is hexadecimal string. Adobe2
write a program to arrange the contents of a 1D array in ascending order  3
write a program structure to find average of given number  1
which one is highest Priority in c? a)=,b)+,c)++,d)==  3
main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } what is the output? Ramco4
What are .h files and what should I put in them?  3
7. Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture8
hi how to convert program from notepad to turboc editor can u please help me  1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com