I note that the toBinary command does not work with integers, only reals. How do you turn an integer into a real? You don't add 0. to it, or multiply it by 1.0, or enter it as 14.0 for example... Is there a trick I am missing?

Thank you.

4 posts
• Page **1** of **1**

I note that the toBinary command does not work with integers, only reals. How do you turn an integer into a real? You don't add 0. to it, or multiply it by 1.0, or enter it as 14.0 for example... Is there a trick I am missing?

Thank you.

Thank you.

- d_motto
**Posts:**35**Joined:**Tue Apr 17, 2012 9:19 am

Hi Dave,

Yes, something very simple: big→ or fromBig (R→I) which you find in both the Integer and Base menus.

I think the command you may really want is toBin, though, which does work with both BigInts and Reals.

The toBinary and fromBinary commands deal with hex, binary, and octal numbers and mainly exist for backwards compatibility to HP calcs. There, a "Binary" number is *not* a number represented by 0s and 1s. Rather it's its own 32- or 64-bit data type that is capable of the functions in the Binary or Base menus of these calcs. You have to convert to a Binary if you want to use these functions and you have to convert back to use Reals. In ND1, BigInts and Reals looking like ints are capable of these functions, and it's not necessary to convert a Real into Binary to make it suitable for these functions. Octal, binary, and hex numbers are converted back into Reals with fromBinary, but all toBinary does is shave off any fractional part from an input Real. The result is still a Real.

And, yes, this function should not give an error when invoked on a BigInt. (Instead, it should be a no-op.) I'll fix that with the next update. Thanks!

Oliver

Is there a trick I am missing?

Yes, something very simple: big→ or fromBig (R→I) which you find in both the Integer and Base menus.

I think the command you may really want is toBin, though, which does work with both BigInts and Reals.

The toBinary and fromBinary commands deal with hex, binary, and octal numbers and mainly exist for backwards compatibility to HP calcs. There, a "Binary" number is *not* a number represented by 0s and 1s. Rather it's its own 32- or 64-bit data type that is capable of the functions in the Binary or Base menus of these calcs. You have to convert to a Binary if you want to use these functions and you have to convert back to use Reals. In ND1, BigInts and Reals looking like ints are capable of these functions, and it's not necessary to convert a Real into Binary to make it suitable for these functions. Octal, binary, and hex numbers are converted back into Reals with fromBinary, but all toBinary does is shave off any fractional part from an input Real. The result is still a Real.

And, yes, this function should not give an error when invoked on a BigInt. (Instead, it should be a no-op.) I'll fix that with the next update. Thanks!

Oliver

- oliver
- Site Admin
**Posts:**433**Joined:**Sat May 01, 2010 2:11 pm

Another (important) thing to know: In ND1, "5." and "5" are Reals. Unlike the 50g in exact mode, "5" does not yield a BigInt. If you want one, you have to manually convert the Real with toBigNum (R→I). (Or use "big5".) (You may also use →big or toBig but this will convert to a BigFloat, if your Real is not a whole number.)

I reckoned that accidental use of Integers (=BigInts in ND1) caused countless problems on the 50g and decided to break with compatibility and not repeat these. (For example, "1 100 FOR i ..." would be a common thing to write. On a 50g this comes with a severe speed penalty, and the author almost certainly meant to write "1. 100. FOR i ...".)

I reckoned that accidental use of Integers (=BigInts in ND1) caused countless problems on the 50g and decided to break with compatibility and not repeat these. (For example, "1 100 FOR i ..." would be a common thing to write. On a 50g this comes with a severe speed penalty, and the author almost certainly meant to write "1. 100. FOR i ...".)

- oliver
- Site Admin
**Posts:**433**Joined:**Sat May 01, 2010 2:11 pm

Funny: I wrote a 'toBin' and called it that:

Perhaps a bit clunky and of course it doesn't check the input, but it works the way I wanted:

Input a number and it returns the binary representation as a vector; I can then use the

Thank you,

Dave Motto

- Code: Select all
`function (x) {`

var b = x.toString(2);

var a = split(b);

return a;

}

Perhaps a bit clunky and of course it doesn't check the input, but it works the way I wanted:

Input a number and it returns the binary representation as a vector; I can then use the

- Code: Select all
`total`

Thank you,

Dave Motto

- d_motto
**Posts:**35**Joined:**Tue Apr 17, 2012 9:19 am

4 posts
• Page **1** of **1**

Users browsing this forum: No registered users and 1 guest