12,750,710 members (37,321 online)
Rate this:
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 20-Jan-13 19:44pm
Teju MB 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).
Alamgirable 21-Jan-13 3:16am

And in simple words 01000100 = 1 and 1 = 01000100 and already programmed on both sides compression and decompression.

Rate this:

## Solution 3

```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")

```
v2
Ashok19r91d 21-Jan-13 4:20am

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...
Rate this:

## Solution 1

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...
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...
Rate this:

## Solution 2

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...
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...

Top Experts
Last 24hrsThis month
 Karthik Bangalore 400 Graeme_Grant 278 F-ES Sitecore 185 OriginalGriff 130 Peter Leow 118
 OriginalGriff 3,853 Peter Leow 2,891 Karthik Bangalore 2,235 ppolymorphe 2,062 Richard MacCutchan 1,464