![]() Now we print the result for checking the bit at m, using an 'AND' operator between the number and the check mask.Now we print the result for toggling the bit at k, using a 'XOR' operator between the number and the toggle mask.Now we print the result for setting the bit (OFF) at j, using an 'AND' operator between the number and the off mask.Now we print the result for setting the bit (ON) at i, using an 'OR' operator between the number and the on mask.This is check mask with 1 at mth position from left and 0 is present at rest of the position and we have achieved this using left shift by m positions.This is a toggle mask with 1 at kth position from left and 0 is present at the rest of the position and we have achieved this using left shift by k positions.And then taking its complement using the (~) operator. This is an off mask with 0 at jth position from left and 1 is present at rest of the position we have achieved this using left shift by j positions.This is an on mask with 1 at ith position from left and 0 is present at rest of the position and we have achieved this using left shift by i positions.After this take a 2's complement of the converted binary number.If the sign is negative, then first of all leave the negative sign behind and convert the decimal number into a binary number.And if the converted number has fewer bits than the possible number of bits then we add zeros at the left of the binary number to make its size equal to the number of possible bits. ![]() It means that if the converted number has more bits than the possible number of bits of a particular type then discard the extra bits from the left.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |