about c

Discussion in 'C Programming' started by beginers of c, Sep 26, 2007.

  1. i have a binary number
    1001 .i have to left shift it to 1 position
    like 0011.if their any datatype or code is available to shift the
    binary numbers
    beginers of c, Sep 26, 2007
    #1
    1. Advertising

  2. beginers of c

    DDD Guest

    On Sep 26, 10:39 pm, beginers of c <> wrote:
    > i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.if their any datatype or code is available to shift the
    > binary numbers


    You have to shift a binary number to left 1 position and you want to
    ask whether there is any code to do this operation?
    I want to know how you get the binary number? from a file or just you
    convert from other none binary number temporary?
    If so, why not doing the shift after you get it as a none binary
    number then convert it back.
    DDD, Sep 26, 2007
    #2
    1. Advertising

  3. beginers of c

    osmium Guest

    "beginers of c" writes:

    >i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.if their any datatype or code is available to shift the
    > binary numbers


    Look up the << and <<= operators.
    osmium, Sep 26, 2007
    #3
  4. On Sep 26, 3:39 pm, beginers of c <> wrote:
    > i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.if their any datatype or code is available to shift the
    > binary numbers


    The easiest way to left shift a number is to use the 'left shift'
    operator << .

    However, 0011 is not a left-shifted form of 1001. Are you sure you
    want to left shift the number?
    J. J. Farrell, Sep 26, 2007
    #4
  5. beginers of c

    osmium Guest

    "J. J. Farrell" writes:

    > On Sep 26, 3:39 pm, beginers of c <> wrote:
    >> i have a binary number
    >> 1001 .i have to left shift it to 1 position
    >> like 0011.if their any datatype or code is available to shift the
    >> binary numbers

    >
    > The easiest way to left shift a number is to use the 'left shift'
    > operator << .
    >
    > However, 0011 is not a left-shifted form of 1001. Are you sure you
    > want to left shift the number?


    I didn't even notice that. If the OP wants a circular shift he will have to
    build it up out of the bits and pieces that C does offer.
    osmium, Sep 26, 2007
    #5
  6. beginers of c

    vin Guest

    On Sep 26, 7:39 am, beginers of c <> wrote:
    > i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.if their any datatype or code is available to shift the
    > binary numbers


    to left shift a number simply use the left shift opreator, which is <<

    syntax: your number << the number of places you want to shift

    hey m a newbie to C, so please tell me if i'm wrong, so that i can
    correct myself.

    Thank you
    vin, Sep 26, 2007
    #6
  7. beginers of c <> writes:
    > i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.if their any datatype or code is available to shift the
    > binary numbers


    That's not a shift. It looks like you want to do a rotate operation.
    C doesn't provide an operator to do that directly, but you can program
    it.

    Incidentally, if you'll try to use better punctuation and
    capitalization, it will be helpful to those of us who are trying to
    help you. Capitalize the word "I" and the first word of each
    sentence. Leave a space or two after the "." at the end of each
    sentence; don't leave a space before it.

    For example:

    I have a binary number 1001. I have to left shift it to 1 position
    like 0011. If their any datatype or code is available to shift the
    binary numbers.

    The grammar and spelling are still a bit off, but we can overlook
    that.

    Also, what *exactly* do you mean when you say you have a binary number
    1001? Do you have a 4-character string with the value "1001"? Do you
    have an integer object whose value would be 1001 if expressed in
    binary (9 decimal)? In C, integers are always stored in binary, but
    the language has no notation for binary constants (it only has
    decimal, octal, and hexadecimal).

    Finally, let me suggest that you choose a more specific subject, so we
    can tell what you're asking about. Everything here is (or should be)
    "about c". A subject like "binary left shift" or "binary left rotate"
    wold have been better.

    Please don't take offense at these suggestions; they're intended to be
    constructive, so we can help you more effectively.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 26, 2007
    #7
  8. beginers of c

    pete Guest

    beginers of c wrote:
    >
    > i have a binary number
    > 1001 .i have to left shift it to 1 position
    > like 0011.


    That's a square root, not a shift.

    > if their any datatype or code is available to shift the
    > binary numbers


    --
    pete
    pete, Sep 26, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page