Ask Your Question

SAGE multiplication in 2^8

asked 2016-09-16 04:18:01 -0500

updated 2017-08-01 05:06:09 -0500

FrédéricC gravatar image

Hi guys, I have a questions:

If I want to do the multiplication 0x09 * x where x is another number hex.

or another example, 0x0d * x, how can I do this in sage?

Because for example when I multiply by 2, I do: x=2*x if x>=256: x=(x-256)^^0x1b

the multplication is in 2⁸ Thank you very much

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2016-09-16 16:21:49 -0500

nbruin gravatar image

Python (and hence sage) understand exactly the hexadecimal notation that you use here, so this just works:

sage: y = 0x0d * 0x0c
sage: y

As you can see, sage will normally print the integer in decimal, even if you have obtained it from integers inputted in hex (the way the integer is obtained is not part of what is remembered. Only its value is). If you want to print it in hex you can do:

sage: y.str(16)
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: 2016-09-16 03:45:08 -0500

Seen: 50 times

Last updated: Sep 16 '16