Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET binary
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
Comments
Teju MB at 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 at 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 at 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: bad
good
Please Sign up or sign in to vote.

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

  Permalink  
v2
Comments
Ashok19r91d at 21-Jan-13 4:20am
   
Accept My Solutions If It Help you in any Way...
Alamgirable at 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 at 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 at 21-Jan-13 7:24am
   
What do you mean by DB.
Ashok19r91d at 21-Jan-13 7:28am
   
DB means Database, It May be a Microsoft Access, SQL Server, XML or Any Other Data File...
Rate this: bad
good
Please Sign up or sign in to vote.

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...
  Permalink  
Comments
Alamgirable at 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 at 21-Jan-13 4:04am
   
If So Then Very Simple, Use Just Simple IF Condition in Program...
Alamgirable at 21-Jan-13 4:08am
   
Can you plz give me a example of its programming.
Ashok19r91d at 21-Jan-13 4:10am
   
View My New Solution...
Rate this: bad
good
Please Sign up or sign in to vote.

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...
  Permalink  
Comments
Alamgirable at 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 at 21-Jan-13 4:05am
   
I Hope You Just Copy my Solution and Paste as New...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 609
1 OriginalGriff 587
2 Maciej Los 325
3 Mathew Soji 195
4 BillWoodruff 190
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100