Getting two's complement representation of an Integer?

Discussion in 'Ruby' started by Kedar Mhaswade, Jan 1, 2011.

  1. Is there a Ruby standard library method to get an Integer's two's
    complement representation (on the given machine) of an Integer?

    to_s(2) does not give the two's complement representation of a negative
    integer.

    Thanks in advance!

    -Kedar

    --
    Posted via http://www.ruby-forum.com/.
    Kedar Mhaswade, Jan 1, 2011
    #1
    1. Advertising

  2. Kedar Mhaswade

    botp Guest

    On Sat, Jan 1, 2011 at 10:43 AM, Kedar Mhaswade
    <> wrote:
    > Is there a Ruby standard library method to get an Integer's two's
    > complement representation (on the given machine) of an Integer?


    try combining fixnum#size and (s)printf/format using %b

    happy new year and best regards -botp
    botp, Jan 1, 2011
    #2
    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.
Similar Threads
  1. Rajesh.Rapaka
    Replies:
    13
    Views:
    1,764
    Patricia Shanahan
    Jul 10, 2006
  2. Mantorok Redgormor

    sign magnitude, ones complement, two's complement

    Mantorok Redgormor, Oct 5, 2003, in forum: C Programming
    Replies:
    8
    Views:
    8,573
    Glen Herrmannsfeldt
    Oct 8, 2003
  3. sarathy

    1's complement and 2's complement

    sarathy, Aug 1, 2006, in forum: C Programming
    Replies:
    20
    Views:
    2,172
    Bo Persson
    Aug 2, 2006
  4. sarathy
    Replies:
    22
    Views:
    2,317
    Bo Persson
    Aug 2, 2006
  5. Roberto Waltman

    2's complement vs. 1's complement vs. ...

    Roberto Waltman, Jun 9, 2011, in forum: C Programming
    Replies:
    4
    Views:
    1,339
    Michael Press
    Jun 14, 2011
Loading...

Share This Page