Question about Bit Manipulation.

This is a discussion on Question about Bit Manipulation. within the C Programming forums, part of the General Programming Boards category; Hi,I'm new to This Forum and New to C as well. I have this Question in my Mind,can someone please ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    18

    Question Question about Bit Manipulation.

    Hi,I'm new to This Forum and New to C as well.
    I have this Question in my Mind,can someone please Answer It.

    Can someone please Explain this Bit manipulation Table.

    Consider multiplication of a number by 2,do this by shift in memory Location.

    Value of m____Bit Representation of m__Bits after Bit Shift________Value in m after bit shift
    1_____________0000 0001____________0000 0010_________________2
    2 ____________0000 0010____________0000 0100_________________4
    3____________ 0000 0011____________0000 0110_________________6


    Please guys I need a Logical Explanation for this.
    I Know its simple,but just can get around It.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Presumably you know which way left is. What exactly is your question?

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    18
    Yes,I know The Table didn't come out properly,but I tried my best to make It appear properly.
    Basically I wanted an Explanation of Bit manipulation in C.

    The Question is
    Q.Shift Bits of memory location m to the left by one position.

    That Table is the answer,but I wanted to know How?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,058
    Perhaps it would help to think in terms of place-value notation.
    Code:
    123 = 1 * 10^2 + 2 * 10^1 + 3 * 10^0
    
    similarly in binary
    0010 = 0 * 2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0 == decimal 2
    0100 = 0 * 2^3 + 1 * 2^2 + 0 * 2^1 + 0 * 2^0 == decimal 4

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In our normal number system (base 10), every time you move a digit one column to the left, you multiply it's value * the base (which is 10).

    00000001 = 1
    00000010 = 1 * 10

    In the binary number system (base 2), every time you move a digit one column to the left,
    you multiply it's value * the base (which is 2).

    00000001 = 1
    00000010 = 1 * 2

    In hexadecimal (base 16), every time you move a digit one column to the left,
    you multiply it's value * the base (which is 16).

    00000001 = 1
    00000010 = 1 * 16

    You see the pattern, no doubt. It's just arithmetic with different number bases.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    18

    Thumbs up

    Thanks for the Answers guys,I'll Try and Brush through and lend a little bit of Brain into the Answers.!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple String Manipulation (Beginner question)
    By valdro in forum C Programming
    Replies: 4
    Last Post: 02-16-2009, 07:16 PM
  2. Bit Shifting Question
    By loko in forum C Programming
    Replies: 10
    Last Post: 09-13-2005, 05:07 PM
  3. bit manipulation in C#
    By luigi40 in forum C# Programming
    Replies: 4
    Last Post: 06-21-2005, 02:15 AM
  4. Question regarding pointer manipulation
    By samadhi in forum C Programming
    Replies: 4
    Last Post: 04-05-2005, 03:57 AM
  5. simple input and string manipulation question
    By Stig in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 01:33 PM

Tags for this Thread


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