Link to home
Start Free TrialLog in
Avatar of testing38
testing38

asked on

How to convert bytes to long...

I think it would be easer to explain what it is I am trying to do rather than just ask a question. I would like to write a program that compresses files and then saves them into a temp. file. This file would contain all the compressed data. I have started to do this as follows:

1)Load the file to be compressed into a byte array
2)compress the byte array with zlib
3)find the origanal and new size of the byte array*
4)get the file name of the compressed file
5)now I start saveing the data into one file
    first I save one byte telling how many bytes are in the compressed files name, next I save that file name. Then I save the origanal and the new size of the byte array as longs(4 bytes each) Then I save save the actual byte array. This is the easy part. (The part I have done) Now I need to read back the file...

First I get the entire file and put it into a byte array. I then use the first byte to tell me how many bytes to read for the file name. Then next 8 bytes(heres the problem) contain the origanal and new(compressed) sizes of the byte array. They are both longs I get these 8 bytes and I don't know how to convert them back into the long long format. To simplafy the problem. Use the put command to put a long number to a file then load that same file into a byte array. This byte array should only be 4 bytes long. I then need to convert those 4 bytes into the origanl long. Wow big... Hope some one can help! Thanks in advance!!!!
ASKER CERTIFIED SOLUTION
Avatar of idt
idt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnn
Johnn

if you unlock the question i've got a function for you that will make it a piece of cake. (depending on how your building the 4 byte block, if you want I've got a function for that too)

John
Avatar of testing38

ASKER

idt: good job! I guess it's not the best way of doing this (as I hear) but It does work and that's what counts.  A+ work
Johnn: nice to hear you have a function. Too bad you did not post it... Then I could at least of considered who to give the points to. Now I only have one choice....
I couldn't post it until I had a chance to provide an answer/
John, I'll give you points for that funtion.