Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

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

asked 10 years ago

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)

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

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

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

sage: 0x100
256
sage: 0x123
291

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

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

Preview: (hide)
link

Comments

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

import csv
    mylist=[]with open('~/Downloads/datasmall.txt', 'rb') as csvfile:
         data = csv.reader(csvfile)for row in data:
             mylist.append([int(row[1]),float.fromhex(row[2])])
Geremia gravatar imageGeremia ( 10 years ago )

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: 10 years ago

Seen: 6,650 times

Last updated: Mar 07 '15