Ask Your Question

How do I deal with large, hex numbers in Sage?

asked 2015-03-07 10:47:47 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

How do I deal with large, hex numbers in Sage (say ones with 256 or 512 bytes)? How would I import them from a CSV file?

(cf. this related answer)

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-03-07 16:13:16 -0500

tmonteil gravatar image

updated 2015-03-07 16:15:09 -0500

You can deal with .csv files by importing the csv module.

Hexadecimals are represented by numbers starting with 0x, see this page :

sage: 0x100
sage: 0x123

To transform an hexadecimal string representation s of a number to a Sage integer (that can be very long), you can do:

sage: s = '123'
sage: ZZ('0x'+s)

If you need more informations, you should provide a sample of your csv file and the result you would expect.

edit flag offensive delete link more


Here's what I did, and it works very well:

import csv
    with open('~/Downloads/datasmall.txt', 'rb') as csvfile:
         data = csv.reader(csvfile)
         for row in data:
Geremia gravatar imageGeremia ( 2015-03-09 15:12:18 -0500 )edit

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: 2015-03-07 10:47:47 -0500

Seen: 705 times

Last updated: Mar 07 '15