Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Fixnum's binary representation

Reply
Thread Tools

Fixnum's binary representation

 
 
Andrew Ballantine
Guest
Posts: n/a
 
      05-04-2005
Guy's this is very neat and it also brings back some memories.

Some years ago I did quite a lot of programming on CDC 6600 & 7600 at the
ULCC. These machines use exactly the same notation. I remember revelling in
having two zeros because I used to use one to mean null (-1) and the other
zero. Yes programming in FORTRAN and writing COMPASS assembler subroutines
when FORTRAN was stumped. Mmm about 1974-1976 I think.

Kind regards,

Andrew Ballantine
----- Original Message -----
From: "Robert Klemme" <(E-Mail Removed)>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <(E-Mail Removed)>
Sent: Wednesday, May 04, 2005 6:09 PM
Subject: Re: Fixnum's binary representation


>
> <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed) ups.com...
> > Thanks, Robert!
> >
> >> For which numbers do you have problems? I don't see any so far

> >
> > I mean...
> > If Bignum#[] is made to simulate 32-bit signed integers, it can't show
> > numbers with more than 32-bit representation.
> > Well, positive numbers will be okay.
> > But what about negative numbers?
> > When can I expect the sign bit?

>
> Well, since Bignums can be arbitrary size, you have to decide. The values
> returned by Fixnum#[] and Bignum#[] represent bits of a two complement's
> arbitrary size binary number. If you view it from this perspective,

you'll
> see that there is no single sign bit. Negative numbers have *all* the
> higher bits set to 1.
>
> > I assume that numbers beyond 32-bit are not suitable for Bignum#[].
> > Do you agree?

>
> Not at all.
>
> >> n = -(1<<100)

> => -1267650600228229401496703205376
> >> 200.times{|i| print i, " ", n[i], "\n"}

> 0 0
> 1 0
> 2 0
> 3 0
> 4 0
> 5 0
> 6 0
> 7 0
> 8 0
> 9 0
> 10 0
> 11 0
> ....
> 95 0
> 96 0
> 97 0
> 98 0
> 99 0
> 100 1
> 101 1
> 102 1
> 103 1
> 104 1
> ....
> 195 1
> 196 1
> 197 1
> 198 1
> 199 1
> => 200
>
> As you clearly see, the representation is ok.
>
> Btw, you'll notice the same effect with Fixnum#[] - because these methods

do
> not represent the actual binary representation in mem but try to represent
> the general concept of signed binary numbers:
>
> >> (-1)[100]

> => 1
> >> (-1)[1<<100]

> => 1
>
> Kind regards
>
> robert
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.11.4 - Release Date: 04/05/2005
>
>




 
Reply With Quote
 
 
 
 
camsight@gmail.com
Guest
Posts: n/a
 
      05-04-2005
Hmmm... this is very interesting.
Thanks.

Sam

 
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
Binary data representation Charles T. C++ 11 02-05-2004 04:06 PM
print format for binary representation Rim Python 3 01-27-2004 08:31 PM
Re: Converting integer to binary representation Mark Dufour Python 5 12-18-2003 05:28 AM
Re: Converting integer to binary representation Harry George Python 1 12-16-2003 02:48 PM
Converting integer to binary representation Mark Dufour Python 0 12-16-2003 02:26 PM



Advertisments