Join us at IRC!
The measure of a mans life is not how well he dies, but how well he lives.
Wednesday, May 23, 2012
Navigation
Members Online
Total Online: 34
Web Spiders: 17
Guests Online: 32
Members Online: 2

Registered Members: 70170
Newest Member: bahmx
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ assigning bit values.

Sqwertle
Member

Posts: 41
Location:
Joined: 25.09.09
Rank:
Wiseman
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.

define
Member

Posts: 201
Location:
Joined: 13.12.08
Rank:
Moderate
Warn Level: 1
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).


If you need to contact me, send me a PM. I will read and/or respond in time.
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.