3

In any python, is there a package out there that helps with adding and subtracting of bytes or byte arrays. Kinda like how this site does binary subtraction and addition.

http://www.csgnetwork.com/binaddsubcalc.html

I want to try to use files as a way to work with big numbers. Instead of storing the information in the memory.

I want to load bytes in, one at a time, manipulate, and keep left over for next byte, and repeat through out the file. Seems it would work. Seems like something someone somewhere would have already done. It would be slower, but it's the sacrifice for being able to work with bigger numbers without using all the ram. Any one know where i can look?

Nice1013
  • 125
  • 2
  • 8
  • You need to be more specific... – juanpa.arrivillaga Apr 03 '17 at 01:46
  • How big are the numbers, out of curiosity? – Ry- Apr 03 '17 at 01:47
  • Really big. Crashed the computer a few times. so bigger than 6gbs i usually have free in ram. – Nice1013 Apr 03 '17 at 01:56
  • You can likely use `int.from_bytes` and `int.to_bytes` and your adding and subtracting will be taken care of. – juanpa.arrivillaga Apr 03 '17 at 01:56
  • Are you proposing to use the files as very very long binary integers, as a list of numbers of a certain size? Because `numpy` will allow you to specify a list's underlying storage. – aghast Apr 03 '17 at 02:02
  • How big is “really big”, though? How are you getting them? (A good sense of scale is important to know what kind of disk representation you’ll need.) – Ry- Apr 03 '17 at 02:03
  • @juanpa.arrivillaga do you know if `int.from_bytes` will use the provided bytes as the underlying representation, or if it tries to build a new object? – aghast Apr 03 '17 at 02:24
  • @AustinHastings It definitely builds a new object *python object*, but I'm not sure if that underlying `int` object uses the bytes directly or allocates new memory for them. – juanpa.arrivillaga Apr 03 '17 at 02:25

0 Answers0