logo

CuriousTab

CuriousTab

Discussion


Home C Programming Bitwise Operators Comments

  • Question
  • Left shifting a number by 1 is always equivalent to multiplying it by 2.


  • Options
  • A. True
  • B. False

  • Correct Answer
  • True 

    Explanation
    0001 => 1
    0010 => 2
    0100 => 4
    1000 => 8

  • Bitwise Operators problems


    Search Results


    • 1. Bitwise & and | are unary operators

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          unsigned char i = 0x80;
          printf("%d\n", i<<1);
          return 0;
      }
      

    • Options
    • A. 0
    • B. 256
    • C. 100
    • D. 80
    • Discuss
    • 3. Assuming a integer 2-bytes, What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%x\n", -1<<3);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. fff8
    • C. 0 
    • D. -1
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          printf("%d %d\n", 32<<1, 32<<0);
          printf("%d %d\n", 32<<-1, 32<<-0);
          printf("%d %d\n", 32>>1, 32>>0);
          printf("%d %d\n", 32>>-1, 32>>-0);
          return 0;
      }
      

    • Options
    • A. Garbage values
    • B. 64 32
      0 32
      16 32
      0 32
    • C. All zeros
    • D. 8 0
      0 0
      32 0
      0 16
    • Discuss
    • 5. What will be the output of the program?
      #define P printf("%d\n", -1^~0);
      #define M(P) int main()\
                   {\
                      P\
                      return 0;\
                   }
      M(P)
      

    • Options
    • A. 1
    • B. 0
    • C. -1
    • D. 2
    • Discuss
    • 6. Bitwise & can be used to divide a number by powers of 2

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. Bitwise & can be used to check if more than one bit in a number is on.

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. In the statement expression1 >> expression2. if expression1 is a signed integer with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer

    • Options
    • A. True
    • B. False
    • Discuss
    • 9. Bitwise & can be used to check if a bit in number is set or not.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.

    • Options
    • A. True
    • B. False
    • Discuss


    Comments

    There are no comments.

Enter a new Comment