ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 20 Oct 2011 04:34:53 +0200how to write .digit() ??https://ask.sagemath.org/question/8398/how-to-write-digit/I create function that want to see result of *example* 128.digit() = [1,1,0,0,0,0,..] like this (not sure)
but when I write in python, it has function .digit() too but it has different use and it can't use with integer number (it use to check digit, right?)
how can i write fucntion .digit() just like in sage into my python program?
thank you for your kindnessWed, 19 Oct 2011 17:06:10 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/Answer by John Palmieri for <p>I create function that want to see result of <em>example</em> 128.digit() = [1,1,0,0,0,0,..] like this (not sure) </p>
<p>but when I write in python, it has function .digit() too but it has different use and it can't use with integer number (it use to check digit, right?) </p>
<p>how can i write fucntion .digit() just like in sage into my python program? </p>
<p>thank you for your kindness</p>
https://ask.sagemath.org/question/8398/how-to-write-digit/?answer=12782#post-id-12782I'm not sure what `[1, 1, 0, 0, 0, 0, ...]` has to do with 128, but if you want the base 10 digits:
>>> a = 1234
>>> [int(d) for d in str(a)]
>>> [1, 2, 3, 4]
For base 2 instead of base 10, try Google. I found [http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python](http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python), for example.
Wed, 19 Oct 2011 20:26:49 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/?answer=12782#post-id-12782Comment by parzan for <p>I'm not sure what <code>[1, 1, 0, 0, 0, 0, ...]</code> has to do with 128, but if you want the base 10 digits:</p>
<pre><code>>>> a = 1234
>>> [int(d) for d in str(a)]
>>> [1, 2, 3, 4]
</code></pre>
<p>For base 2 instead of base 10, try Google. I found <a href="http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python">http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python</a>, for example.</p>
https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21080#post-id-21080Another link: http://stackoverflow.com/questions/2267362/convert-integer-to-a-string-in-a-given-numeric-base-in-pythonThu, 20 Oct 2011 04:34:53 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21080#post-id-21080Comment by John Palmieri for <p>I'm not sure what <code>[1, 1, 0, 0, 0, 0, ...]</code> has to do with 128, but if you want the base 10 digits:</p>
<pre><code>>>> a = 1234
>>> [int(d) for d in str(a)]
>>> [1, 2, 3, 4]
</code></pre>
<p>For base 2 instead of base 10, try Google. I found <a href="http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python">http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python</a>, for example.</p>
https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21085#post-id-21085I thought the question was how to do it in Python, not in Sage.Wed, 19 Oct 2011 20:44:04 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21085#post-id-21085Comment by DSM for <p>I'm not sure what <code>[1, 1, 0, 0, 0, 0, ...]</code> has to do with 128, but if you want the base 10 digits:</p>
<pre><code>>>> a = 1234
>>> [int(d) for d in str(a)]
>>> [1, 2, 3, 4]
</code></pre>
<p>For base 2 instead of base 10, try Google. I found <a href="http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python">http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python</a>, for example.</p>
https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21086#post-id-21086There's also the .digits() method, which has a base option (e.g. 1234.digits(2) = [0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1]).Wed, 19 Oct 2011 20:34:27 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21086#post-id-21086Comment by DSM for <p>I'm not sure what <code>[1, 1, 0, 0, 0, 0, ...]</code> has to do with 128, but if you want the base 10 digits:</p>
<pre><code>>>> a = 1234
>>> [int(d) for d in str(a)]
>>> [1, 2, 3, 4]
</code></pre>
<p>For base 2 instead of base 10, try Google. I found <a href="http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python">http://stackoverflow.com/questions/187273/base-2-binary-representation-using-python</a>, for example.</p>
https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21084#post-id-21084Ah, you're right. I got it backwards.Wed, 19 Oct 2011 21:10:21 +0200https://ask.sagemath.org/question/8398/how-to-write-digit/?comment=21084#post-id-21084