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 Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are identifiers in c?

640


Is c is a high level language?

626


Why main is used in c?

595


What are the types of operators in c?

620


Explain two-dimensional array.

633






What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1362


What are pointers? What are stacks and queues?

585


What is omp_num_threads?

587


What are the data types present in c?

633


What are the uses of a pointer?

687


What is meant by 'bit masking'?

892


Why can arithmetic operations not be performed on void pointers?

594


How do I create a directory? How do I remove a directory (and its contents)?

611


What are the types of assignment statements?

635


An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

692