Example a=8
a.binary() # prints 1000
How can I store this in an array
1 | initial version |
Example a=8
a.binary() # prints 1000
How can I store this in an array
Example
a=8
a.binary() # prints 1000Given a Sage integer, I wish to obtain the list of its binary digits.
How can I store this in get that?
So far, I found the binary
method of Sage integers.
Given an arrayinteger, that method returns its binary expansion as a string.
For example:
sage: a = 8
sage: a.binary()
'1000'
Given a Sage integer, Thanks for the response
x=3 z=IncreasingArrays() z=x.binary()
for i in range(x): if(z[i]==1): print (' ',2^i) #Not printing here
I wish want to obtain the list of its print if binary digits.value is 1
And raise it to power 2
For loop isn't printing print statement also Please help me with these for loops and also how to store values in an array
in C I go
int a[6]; for(i=2;i<=5;i++) { a[i]=1; }
Here like this in C, array values are set.
How can I get that?to do the same in sage please help
So far, I found the binary
method of Sage integers.
Given an integer, that method returns its binary expansion as a string.
For example:
sage: a = 8
sage: a.binary()
'1000'
Thanks for the response
x=3 z=IncreasingArrays() z=x.binary()
for i in range(x): if(z[i]==1): print (' ',2^i) #Not printing here
I want to print if binary value is 1 And raise it to power 2
For loop isn't printing print statement also Please help me with these for loops and also how to store values in an array
in C I go
int a[6]; for(i=2;i<=5;i++) { a[i]=1; }
Here like this in C, array values are set.
How to do the same in sage please help
Given a Sage integer, I wish to obtain the list of its binary digits.
How can I get that?
So far, I found the binary
method of Sage integers.
Given an integer, that method returns its binary expansion as a string.
For example:
sage: a = 8
sage: a.binary()
'1000'
Thanks for the response
x=3 z=IncreasingArrays() z=x.binary()
response.
Here is a follow-up question.
x = 3
z = IncreasingArrays()
z = x.binary()
for i in range(x):
if(z[i]==1):
print (' ',2^i) #Not if z[i] == 1:
print(' ', 2^i) # Not printing herehere
I want to print if binary value is 1
1.
And raise it to power 2
For 2.
The for
loop isn't printing print statement also
also.
Please help me with these for loops and also how to store values in an array
in array.
In C I go
go:
int a[6];
for(i=2;i<=5;i++) for(i = 2 ; i <= 5 ; i++) { a[i]=1; }a[i] = 1 ; }
Here like this in C, array values are set. set.
How to do the same in sage Sage please helphelp.