Ask Your Question
0

Ignoring binary string monoid

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

anonymous user

Anonymous

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

01000001

sage: ascii_integer(B)

65

sage: parent(B)

Free binary string monoid

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

sage:

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

tmonteil gravatar image

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

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))
262145

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

sage: str(B)
'01000001'

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
65
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

Stats

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

Seen: 546 times

Last updated: Jun 02 '20