Thread: Bitwise operators

  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, 11:37 AM
  2. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 02: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, 04:20 PM
  5. Bitwise operators. What's this????????
    By money? in forum C Programming
    Replies: 20
    Last Post: 06-17-2003, 06:03 PM