[sage-edu] integer, tostring, length?

2009-09-19 Thread calcpage

Sorry, silly question:

OK, I know I've done this in Sage before, but I can't remember for the 
life of me how.

I'm writing a program that computes large integers and tests for 
primality.  What I'd like to do is print out the integer and how many 
digits it has.  I seem to remember having to convert the integer to a 
string and then find its length() or size().

Could someone please remind me how this works?

TIA,
A. Jorge Garcia
http://calcpage.tripod.com

Teacher & Professor
Applied Mathematics, Physics & Computer Science
Baldwin Senior High School & Nassau Community College




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to sage-edu@googlegroups.com
To unsubscribe from this group, send email to 
sage-edu+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en
-~--~~~~--~~--~--~---



[sage-edu] Re: integer, tostring, length?

2009-09-19 Thread David Joyner

Do you mean this?

sage: n = 1234567890123456789
sage: len(str(n))
19


On Sat, Sep 19, 2009 at 10:14 AM,   wrote:
>
> Sorry, silly question:
>
> OK, I know I've done this in Sage before, but I can't remember for the
> life of me how.
>
> I'm writing a program that computes large integers and tests for
> primality.  What I'd like to do is print out the integer and how many
> digits it has.  I seem to remember having to convert the integer to a
> string and then find its length() or size().
>
> Could someone please remind me how this works?
>
> TIA,
> A. Jorge Garcia
> http://calcpage.tripod.com
>
> Teacher & Professor
> Applied Mathematics, Physics & Computer Science
> Baldwin Senior High School & Nassau Community College
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to sage-edu@googlegroups.com
To unsubscribe from this group, send email to 
sage-edu+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en
-~--~~~~--~~--~--~---



[sage-edu] Re: integer, tostring, length?

2009-09-19 Thread calcpage

Yes, that was it!  Thank you!

How easy it is to forget syntax in one environment when using another.  
I was teaching java all day yesterday and I just couldn't remember the 
equivalent in Sage!

BTW, I had worksheets in sagenb online where I saved a lot of 'notes to 
self' whenever I figured out something like this so I could look it up 
later as needed.  Well those worksheets are now blank and I don't know 
why!

HTH,
A. Jorge Garcia
http://calcpage.tripod.com

Teacher & Professor
Applied Mathematics, Physics & Computer Science
Baldwin Senior High School & Nassau Community College


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to sage-edu@googlegroups.com
To unsubscribe from this group, send email to 
sage-edu+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en
-~--~~~~--~~--~--~---



[sage-edu] Re: integer, tostring, length?

2009-09-19 Thread Dan Drake
On Sat, 19 Sep 2009 at 10:25AM -0400, David Joyner wrote:
> Do you mean this?
> 
> sage: n = 1234567890123456789
> sage: len(str(n))
> 19

There's also n.ndigits(), which I think directly returns the number of
digits without doing any conversion to a string. You can even specify
different bases, so if n = 8, you get 1 for base 10, and 3 for base 2.
You can also put in really large bases: 

sage: n = 1025
sage: n.ndigits(1024)
2


Dan

-- 
---  Dan Drake
-  http://mathsci.kaist.ac.kr/~drake
---


signature.asc
Description: Digital signature