Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Alternatively, if we want the binary representation as a p h o n e number:

sage: a = 189866136719308462018271159242437168532L
sage: bin(a)

sage: type(bin(a))
<type 'str'>

This is similar to

sage: hex(a)
'0x8ed6e347bb3a795529f751a9c8d00d94L'
sage: oct(a)
'02166556150756635171252247672432471064006624L'

We can check that this matches the bits solution

sage: ZZ(a).bits() == [ int(s) for s in bin(a)[:1:-1] ]
True

Alternatively, if we want the binary representation as a p h o n e number:

sage: a = 189866136719308462018271159242437168532L
sage: bin(a)

sage: type(bin(a))
<type 'str'>

This is similar to

sage: hex(a)
'0x8ed6e347bb3a795529f751a9c8d00d94L'
sage: oct(a)
'02166556150756635171252247672432471064006624L'

We can check that this matches the bits solution from the answer of slelievre:

sage: ZZ(a).bits() == [ int(s) for s in bin(a)[:1:-1] ]
True

Of course.

Note: Repeated times i tried to post versions of this answer. (The solution was to take a shower, then i wrote the word phone in an "unexpected" way. It seems that we cannot post the string pho.. number followed by an obvious such number here.)

Alternatively, if we want the binary representation as a p h o n e number:

sage: a = 189866136719308462018271159242437168532L
sage: bin(a)
'0b10001110110101101110001101000111101110110011101001111001010101010010100111110111010100011010100111001000110100000000110110010100'

sage: type(bin(a))
<type 'str'>

This is similar to

sage: hex(a)
'0x8ed6e347bb3a795529f751a9c8d00d94L'
sage: oct(a)
'02166556150756635171252247672432471064006624L'

We can check that this matches the bits solution from the answer of slelievre:

sage: ZZ(a).bits() == [ int(s) for s in bin(a)[:1:-1] ]
True

Of course.

Note: Repeated times i tried to post versions of this answer. (The solution was to take a shower, then i wrote the word phone in an "unexpected" way. It seems that we cannot post the string pho.. number followed by an obvious such number here.)