Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to compress binary data.
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
Comments
The Doer 21-Jan-13 1:10am    
how your 01000100 converted to "1"??
Is there any algorithm ?

What if u have binarCode as "11110000" this would be 1 or 0??

InSufficient information..!
Alamgirable 21-Jan-13 3:13am    
i want to make a very little program in which 01000100 and 01000010 already programmed and they are equal to 1 and 0.At the compression time the program already know that:
01000100 = 1 and 01000010 = 0 and on decompression it know:
1 = 01000100 and 0 = 01000010.
But its files those saved in hard driver are equal to 2 bits.(May you understand my question).
And sorry for bad english
Alamgirable 21-Jan-13 3:16am    
And in simple words 01000100 = 1 and 1 = 01000100 and already programmed on both sides compression and decompression.

VB
Function CompressText (ByVal TextToCompress as String) As Integer
If TextToCompress = "01000100" Then Return 1
If TextToCompress = "01000010" Then Return 0
End Function

Function DeCompressText (ByVal TextToDeCompress as String) As String
If TextToDeCompress = 1 Then Return "01000100" 
If TextToDeCompress = 0 Then Return "01000010"
End Function

'Call Above Function When-ever and Where-ever it Necessary...
'Example:
'TextBox1.Text = DeCompressText(1)
'TextBox2.Text = CompressText("01000100")
 
Share this answer
 
v2
Comments
Ashok19r91d 21-Jan-13 4:20am    
Accept My Solutions If It Help you in any Way...
Alamgirable 21-Jan-13 6:49am    
I have another question. You declare variable as integer.
Integer is a variable which storage size is 2bytes in visual basic.
So, my concern is with data compression the return 1 and 0 is equal to 2bytes.
Currently the data is not compressed.
Ashok19r91d 21-Jan-13 6:56am    
Mumm, May be You are Right in Your Point of View, But Whenever You are Going to Save these 0 or 1 in DB, It automatically Converted into Bit DataType(Boolean).
So No Need to Worry about Storage Size,

But If You Don't Need to Store These Value in DB, But Need to Compress DataType Then, Replace All "INTEGER" to "BYTE" in my Above Code...
Alamgirable 21-Jan-13 7:24am    
What do you mean by DB.
Ashok19r91d 21-Jan-13 7:28am    
DB means Database, It May be a Microsoft Access, SQL Server, XML or Any Other Data File...
you can't Perform That Operation, With Build-in Visual Basic Function and even User Defined Function (unless you have your Very own Algorithm), If you have Your Very Own Logic on this Then Consider Improving Your Solution with Your Algorithm.

But in My Opinion, There are 256 (2^8) Binary Value you get using 8 Set of 0 and 1.

Then How will you consolidate these 256 Values with only 2 Value?

If You need to Convert Binary Value into Decimal or HexaDecimal Value? Reply to This Solution, I'll Help...
 
Share this answer
 
Comments
Alamgirable 21-Jan-13 3:28am    
As i said i have only two values 01000100 and 01000010 (only 2bytes not more then 2).And i want to make them equal 1 and 0.One is equal 1 and the other is equal 0. I have only 2 values not 256.
Ashok19r91d 21-Jan-13 4:05am    
I Hope You Just Copy my Solution and Paste as New...
You can't Perform That Operation, With Build-in Visual Basic Function and even User Defined Function (unless you have your Very own Algorithm), If you have Your Very Own Logic on this Then Consider Improving Your Solution with Your Algorithm.

But in My Opinion, There are 256 (2^8) Binary Value you get using 8 Set of 0 and 1.

Then How will you consolidate these 256 Values with only 2 Value?

If You need to Convert Binary Value into Decimal or HexaDecimal Value? Reply to This Solution, I'll Help...
 
Share this answer
 
Comments
Alamgirable 21-Jan-13 3:22am    
As i said i have only two values 01000100 and 01000010 (only 2bytes not more then 2).And i want to make them equal 1 and 0.One is equal 1 and the other is equal 0.
I have only 2 values not 256.
Ashok19r91d 21-Jan-13 4:04am    
If So Then Very Simple, Use Just Simple IF Condition in Program...
Alamgirable 21-Jan-13 4:08am    
Can you plz give me a example of its programming.
Ashok19r91d 21-Jan-13 4:10am    
View My New Solution...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900