Ask Your Question

Ignoring binary string monoid

asked 2020-06-02 12:55:46 +0200

anonymous user


I was just wondering what can I do to convert the binary digits (for ex. ASCII) shown below to integers.

sage: from sage.crypto.util import ascii_to_bin

sage: from sage.crypto.util import ascii_integer

sage: bin=BinaryStrings()

sage: B=bin.encoding("A"); B


sage: ascii_integer(B)


sage: parent(B)

Free binary string monoid

sage: parent(ascii_integer(B)) <type 'int'="">


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-02 13:28:01 +0200

tmonteil gravatar image

updated 2020-06-02 14:42:46 +0200

Let me just add a warning: if you want to make B an integer, as in your previous question, you can first try:

sage: ZZ(str(B))

which looks pretty weird. This is due to the fact that the number:

sage: str(B)

starts with a 0, indicating that it should undertand the representation to be in octal, while you want it in binary. Fortunately, you can specify the base in the conversion:

sage: b = ZZ(str(B), base=2) ; b
sage: b.parent()
Integer Ring
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-06-02 12:55:46 +0200

Seen: 72 times

Last updated: Jun 02 '20