June 16th, 2013, 06:18 AM
Converting text file to binary
I have text file with numbers..
and i want to save this file in the memory as binary file.
I will explain..
Right now, this file weight is 11 bytes (1 byte per character).
When convertin the presentation of each number to log2 i can save each number as 1/2 bytes.
123=> 1111011 = 1byte
1045=> 10000010101 = 2 bytes
4928=> 1001101000000 = 2 bytes
How can i do that? easy way?
June 16th, 2013, 10:25 AM
Last edited by FishMonger; June 16th, 2013 at 10:27 AM.
June 16th, 2013, 12:16 PM
So do I. Why would anyone want to save 6 bytes with today's hardware?
Originally Posted by FishMonger
June 16th, 2013, 12:28 PM
June 16th, 2013, 12:38 PM
Can you explain yourself?
Originally Posted by Laurent_R
Maybe i am missing somthing that i dont know..
I am just trying to save disk space
June 16th, 2013, 12:49 PM
Well, there are core modules such as this:
which is why the XY problem was mentioned, I suspect. There may be easier/better ways to get to your end goal.
June 16th, 2013, 03:53 PM
Just explain what you really need, rather than how to achieve the way you think is the right way to do it, but might simply not be the best.
June 16th, 2013, 04:06 PM
I will try to explain what i need.
i have file with many numbers, each number is line number in other reference_file.
for example if i have 1342.
that is mean that i need to remember line 1342 in the reference file to represent the new file (each line contain some text).
i have billions like this.
So i am looking for a better way to save a disk place instead the regular format (characters.)
Maybe creating a reference will be better instead of line number?
June 16th, 2013, 07:50 PM
To me, that's a database. An integer is an excellent key, also.
Of course, without knowing more I question whether these should all exist in a single flat file or table, or whether they could be split into different categories, etc.
June 16th, 2013, 11:37 PM
First you say that your file is only 11 bytes containing an integer per line, now you say you have billions of lines like that, which is certainly going to be greater than 11 bytes.
Saving disk space is not the main concern, or at least it shouldn't be. The main concern should be how to access that data in an efficient way.
You haven't provided enough info for us to say with any confidence how you should store/access the data, but I'll agree with keath and say you should be using a database.
If you don't want to (note that I said "don't want to" not "can't") use a database, then instead of tracking the desired line numbers in that separate file, you should be tracking the desired byte offsets.