13,402,593 members (48,223 online)
See more:
Suppose i have two binary values 01000100 and 01000010.
I want to compress them like this:

```01000100 = 1
01000010 = 0```

After compress the 2bytes would be converted to 2bits
and decompress them like:

```1 = 01000100
0 = 01000010```

After decompress the 2bits would be converted to 2bytes

Actually i want to compress 2byte(binary) to 2bits.And after decompress the data again convert to 2byte.
How can i do it in visual basic. I am a new in computer programming
Posted 5-Feb-13 9:03am

"Anyone knows C++"?! Well, well... :-)
"Compress"?! Total gibberish, sorry. You don't understand something very basic, but I cannot figure out what...
—SA
anonymous10 6-Feb-13 10:58am

i have only 2 values 01000100 and 01000010 not 65,532 or 256.I want to make compressor which holds only 2 values and also decompressor.

You apparently have no idea what is a number, don't see a difference between string and number. Your question makes no sense at all. You cannot get help before you understand the very basics, but not on this "question" which is based on some most basic misconceptions.
—SA
anonymous10 6-Feb-13 12:24pm

ok. let see i chat online with my friends daily.i observe that the character like: "this" "is" "a" "why" etc.These words contains 8bits per character.i want to make this = 1,is = 0,a = 10,why = 01 in binary. like:this = 4bytes when i typed this to anyone on chat the only one bit travel through internet and again in his system it will become 4bytes. may know you understand something.

No need to understand this... this is helpless...
—SA
Matthew Faithfull 5-Feb-13 14:26pm

You need to decide whether this is Visual Basic or a C++ question because the answer will be very different in each case.
You also need to be able to explain exactly why 68 => 1 but 66 => 0. Once you are able to explain this clearly enough it can be expressed in the language of your choice.
anonymous10 6-Feb-13 12:07pm

sorry this is c++ question.
Albert Holguin 5-Feb-13 21:56pm

what you're looking for is... magic... sorry, couldn't help myself.. but more seriously compression is somewhat of an advanced topic.
anonymous10 6-Feb-13 10:57am

i have only 2 values 01000100 and 01000010 not 65,532 or 256.I want to make compressor which holds only 2 values and also decompressor.

## Solution 2

Pretty simple if you only have 2 input and 2 output values.

```char Compress(char in)
{
if(68 == in) return 1;  // 01000100 -> 1
if(66 == in) return 0;  // 01000010 -> 0
return -1;              // invalid
}

char Decompress(char in)
{
if(1 == in) return 68;  // 1 -> 01000100
if(0 == in) return 66;  // 0 -> 01000010
return -1;              // invalid
}```

Your problem description I think was the problem here...
anonymous10 7-Feb-13 8:15am

Thanks man finally the person who understand me(after 2days):laugh
anonymous10 7-Feb-13 8:30am

But how can i read these binary values from files and compress them.
For example:
I have a text file in my hard disk in which i have only two numbers 68 and 66.
i want to load this file in c++ then compress this file and save a new file in my hard disk.
I now "fstream" in c++ but how can i use your method with this.
H.Brydon 7-Feb-13 12:34pm

You are asking questions that are so fundamental it is hard to answer them. You really need to pursue your training books/manuals/instructor. What you are asking about here should be found in "input/output" or "I/O" section of any programming book.
anonymous10 7-Feb-13 13:18pm

I just want to read some specific numbers.In text file i have numbers from 1 to 100.i want to read some specific numbers like 8,9,10 from text file.
anonymous10 7-Feb-13 8:34am

Actually i am c++ beginner and i ask this question just for knowledge.

## Solution 1

You can't do it - except in the trivial case you are giving already which is easy:
```1) Is value equal to 0?
2) if yes, output value is 01000010
3) if no, output value is 01000100```

Two bits can only hold 4 values:
```00
01
10
11```

So the other 252 possible combinations you can get into 8 bits have nowhere to be stored. Compression algorithms work by finding patterns in numbers (in essence) and require an amount of overhead to store information about the compression method - with only eight bits of data there is insufficient information for a pattern to be determined - and with overhead you would end up with a longer output than input!
Klaus-Werner Konrad 6-Feb-13 10:36am

Worse - he wants to compress 2 bytes to 2 bits, so there are 65,532 other possible values :-)
anonymous10 6-Feb-13 10:52am

i have only 2 values 01000100 and 01000010 not 65,532 or 256.I want to make compressor which holds only 2 values and also decompressor.
OriginalGriff 6-Feb-13 11:03am

if you only have two values, that's not a compressor - it's a bit test: 0 or 1.
anonymous10 6-Feb-13 11:13am

what i am trying to say is that i have only two binary values.01000100 and 01000010.
First in compressor i want two make then equal 1 and 0.
like:
01000100 = 1
01000010 = 0

after that the data which is stored in harddisk is 2bits.
after decompression it will become again 2bytes.

like:
1 = 01000100
0 = 01000010
OriginalGriff 6-Feb-13 11:16am

Yes I understand that - but it's just a comparison / bit test - there is no compression / decompression involved!
What part of it is giving you problems?
anonymous10 6-Feb-13 11:18am

can you please give me little bit code example or you know any tutorial which is helpful for that.
OriginalGriff 6-Feb-13 11:34am

To compare a byte? Or check a bit? Both are trivial operations, so I can't help thinking you want something else - but I don't know what...
anonymous10 6-Feb-13 12:03pm

ok. let see i chat online with my friends daily.i observe that the character like: "this" "is" "a" "why" etc.These words contains 8bits per character.i want to make this = 1,is = 0,a = 10,why = 01 in binary.

like:this = 4bytes when i typed this to anyone on chat the only one bit travel through internet and again in his system it will become 4bytes.
may know you understand something.
Klaus-Werner Konrad 6-Feb-13 12:25pm

Ok - YOU should THINK FIRST and THEN ask a question.
And, if someone requests more information about the subject, you should answer that request, so we are able to help you ...
You ask in C++ forum and say 'How can I do it in Visual Basic'.
You say 'I have only 2 (two) values, and you say 'binary values'.
NOW you talk about a collection of strings; that's something complete different.
So, please, try to describe what you really want to achieve, and specify the language you want to use for it
OriginalGriff 6-Feb-13 12:26pm

No chance! :laugh:
What happens if you typed "this is a banana"?
What value do you send for the last word?
You can do this kind of thing, provided you run software on both ends which encodes and decodes the data *and* you agree in advance to use a specific, limited vocabulary. But otherwise...do you have any idea how many words there are in English?
approx 250,000 distinct words (but the total count is just over a million, because of plurals, and so forth).

I would abandon this idea - it probably won't significantly reduce traffic size anyway, because an internet packet has a minimum size - 64 bytes - so if you "compress" your message the chances are that the system will immediately pad it out to a suitable size anyway! :laugh:
anonymous10 6-Feb-13 12:36pm

Bro you only suppose that i have only words "this" "is" "a" "why" no more.i have just 4 words.
anonymous10 6-Feb-13 12:57pm

please check this out:
OriginalGriff 6-Feb-13 14:00pm

You can have a packet which contains only one bit of user data - but the minimum size of the whole packet, including the user data and the necessary header info is 64 bytes. Please check this out:
http://en.wikipedia.org/wiki/IPv4#Packet_structure
Maxim Kartavenkov 6-Feb-13 23:50pm

I think he just at beginning of the cryptography, this way in compression called "vlc" or Variable-Length code, two numbers you may use this way but more numbers are coded with prefixes. Mostly uses in video/audio compression. http://en.wikipedia.org/wiki/Variable-length_code
So, he is correct that he calls that as compression.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 265 Richard MacCutchan 110 F-ES Sitecore 80 John Simmons / outlaw programmer 70 phil.o 60
 OriginalGriff 5,344 Maciej Los 2,800 Richard MacCutchan 1,868 CPallini 1,690 RickZeeland 1,099

Advertise | Privacy |
Web01 | 2.8.180218.2 | Last Updated 6 Feb 2013