Bitwise operators

This is a discussion on Bitwise operators within the C Programming forums, part of the General Programming Boards category; So I just finished reading the bitwise operators tutorial. I read that using the leftshift operators, one can raise a ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Bitwise operators

    So I just finished reading the bitwise operators tutorial. I read that using the leftshift operators, one can raise a number to a power.

    Code:
    [variable]<<[number of places]
    In my code I've done this:
    Code:
    printf("%d", 5<<2);
    5 to the power of 2 is 5*5 which is 25 but the result is 20. Any reason why? Is there something I'm missing?

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Never mind. Every move to the left is the the power of 2. I re-read the tutorial and picked up really fast. Sorry guys XD. Misread things.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    1 | 2 | 4 | 8 | 16 | 32 | 64 | 128

    That's a computer!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Operators
    By rrc55 in forum C Programming
    Replies: 6
    Last Post: 04-30-2009, 12:37 PM
  2. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 03:31 PM
  3. bitwise and arithmetic Operators
    By Whiteghost in forum C Programming
    Replies: 4
    Last Post: 12-28-2006, 02:13 PM
  4. Bitwise Operators, Help!!
    By Mini__C in forum C Programming
    Replies: 6
    Last Post: 07-14-2004, 05:20 PM
  5. Bitwise operators. What's this????????
    By money? in forum C Programming
    Replies: 20
    Last Post: 06-17-2003, 07:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21