Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Getting two's complement representation of an Integer?

Reply
Thread Tools

Getting two's complement representation of an Integer?

 
 
Kedar Mhaswade
Guest
Posts: n/a
 
      01-01-2011
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/.

 
Reply With Quote
 
 
 
 
botp
Guest
Posts: n/a
 
      01-01-2011
On Sat, Jan 1, 2011 at 10:43 AM, Kedar Mhaswade
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2's complement vs. 1's complement vs. ... Roberto Waltman C Programming 4 06-13-2011 11:26 PM
1's complement and 2's complement sarathy C++ 22 08-02-2006 05:53 PM
1's complement and 2's complement sarathy C Programming 20 08-02-2006 05:53 PM
float or double's two's complement representation. Rajesh.Rapaka Java 13 07-10-2006 04:54 AM
sign magnitude, ones complement, two's complement Mantorok Redgormor C Programming 8 10-07-2003 11:52 PM



Advertisments