Ask Your Question

Revision history [back]

You can make a conversion:

sage: b = ascii_to_bin('Hi')[4]
sage: b
1

Unfortunately, there is no direct convertion to ZZ:

sage: ZZ(b)
TypeError: unable to coerce <class 'sage.monoids.string_monoid_element.StringMonoidElement'> to an integer

but you can first make b a string an then an integer:

sage: a = ZZ(str(b)) ; a
1
sage: a.parent()
Integer Ring

You can make a conversion:

sage: b = ascii_to_bin('Hi')[4]
sage: b
1

Unfortunately, there is no direct convertion conversion to ZZ:

sage: ZZ(b)
TypeError: unable to coerce <class 'sage.monoids.string_monoid_element.StringMonoidElement'> to an integer

but you can first make b a string an then an integer:

sage: a = ZZ(str(b)) ; a
1
sage: a.parent()
Integer Ring