shifting? division?

This is a discussion on shifting? division? within the C Programming forums, part of the General Programming Boards category; I was hoping someone could maybe write an example to better explain to me this idea. i know its true ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    shifting? division?

    I was hoping someone could maybe write an example to better explain to me this idea. i know its true but I'm having a hard time understanding it,
    so its possible to shift a value and by shifting the value its basically like dividing it by a power of 2?? i think or something like that can someone explain by giving an example on how that really works in a C program.

  2. #2
    Registered User jimtuv's Avatar
    Join Date
    May 2010
    Location
    Sylvania, Ohio
    Posts
    94
    consider the following in binary.

    0001 = 1 decimal

    0010 = 2 decimal

    0100 = 4 decimal

    1000 = 8 decimal

    10000 = 16 decimal

    100000 = 32 decimal

    see how as the bit shifts to the left the number is multiplied by 2 each move. Division by 2 is just a shift to the right. Also you could read this http://en.wikipedia.org/wiki/Bitwise_operation
    Last edited by jimtuv; 06-09-2010 at 02:10 PM.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    okay so if its

    00101110 and i shift it
    >> 3;
    wiil that divivde the binary by 8

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,167
    Yep. It will divide the decimal number by 8.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get jiffies?
    By pgzh in forum Linux Programming
    Replies: 6
    Last Post: 03-17-2008, 10:30 AM
  2. pseudo code for division
    By svaidya in forum C Programming
    Replies: 14
    Last Post: 05-31-2007, 01:48 PM
  3. modulo 2 division question help
    By shaq8u in forum C Programming
    Replies: 9
    Last Post: 08-20-2003, 08:37 AM
  4. shifting numbers
    By kurz7 in forum C Programming
    Replies: 1
    Last Post: 08-06-2003, 12:38 PM
  5. Modular Division problem
    By Malek in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2003, 06:08 PM

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