Ask Your Question
0

SAGE multiplication in 2^8

asked 2016-09-16 11:18:01 +0200

manu4912 gravatar image

updated 2017-08-01 12:06:09 +0200

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
3

answered 2016-09-16 23:21:49 +0200

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
156

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)
'9c'
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: 2016-09-16 10:45:08 +0200

Seen: 699 times

Last updated: Sep 16 '16