Ask Your Question
1

How to identify binary digits as integers?

asked 2020-06-02 03:18:35 -0500

akly gravatar image

I would like to know how to recognize the ASCII binary codes of a string as integers values. Look at the following example.

sage: from sage.crypto.util import ascii_to_bin

sage: ascii_to_bin('Hi')

0100100001101001

sage: ascii_to_bin('Hi')[4]

1

sage: ascii_to_bin('Hi')[4] in ZZ

False

sage:

I would be thankful if I get some tips on how to identify the binary digits as integers.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-06-02 06:23:28 -0500

tmonteil gravatar image

updated 2020-06-02 07:40:52 -0500

You can make a conversion:

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

Unfortunately, there is no direct 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
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

Stats

Asked: 2020-06-02 03:18:35 -0500

Seen: 27 times

Last updated: Jun 02