Ask Your Question

VivekGandhi's profile - activity

2019-09-27 11:24:47 +0100 commented answer sage code for decimal to binary expansion

b = a.digits(2); b.reverse(); ''.join(map(str,b)) pretty much does the same thing as a.binary(). Doing this with other primitive data types can be done using the Python 'struct' package. For example, for floats: ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!f', num)). Anyone has any idea how to print the binary representation for Sage ring data types such as Rationals?