Follow us on Twitter!
Understanding is the answer, hatred is the problem, and hackers are the slaves abused and destroyed in the process of peace online - Deshouleres
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 29
Guests Online: 24
Members Online: 5

Registered Members: 82895
Newest Member: kevy90
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ assigning bit values.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-02-10 05:29
I'm trying to create a simple compression program that will take the most frequently appearing character and assign it a value of 0, the second most frequent 1, third 10 and so forth. This will ultimately result in a smaller file. The two questions I have are: How do I create a file that doesn't contain more characters (the third character being represented by 10 would result in a much larger file)? How would I tell the compiler to store the characters as the exact bits I want?
Author

RE: C++ assigning bit values.


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-02-10 16:10
Sqwertle wrote:
I'm trying to create a simple compression program that will take the most frequently appearing character and assign it a value of 0, the second most frequent 1, third 10 and so forth. This will ultimately result in a smaller file. The two questions I have are: How do I create a file that doesn't contain more characters (the third character being represented by 10 would result in a much larger file)? How would I tell the compiler to store the characters as the exact bits I want?

It's early, but I'll take a stab at this one.

Generally, you're storing ASCII characters in a text file (forget about Unicode for a minute). ASCII is a character set made up of 128 regular character codes and 128 extended character codes that relate to letters or symbols. That's 1 byte (128 or 2^7) and 1 byte (128 or 2^7), but you only use a single byte to represent normal text.

Thus to save your binary representations to a file, you do not write the actual binary to the file but, rather, write the ASCII character code for the decimal equivalent of the binary representation.

Then, when you're reading it in, you can get the ordinal of the ASCII character and convert that back to binary. When you're reading it in C++, you might want to read the file back in using binary I/O for greater precision (just adding an ios::binary in the arguments, I think).