Click here to Skip to main content
16,010,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending email Pin
kpuneeth711-Mar-10 20:46
kpuneeth711-Mar-10 20:46 
Questionhow to open excel file for edit and save back into the same file. Pin
neodeaths11-Mar-10 15:52
neodeaths11-Mar-10 15:52 
AnswerRe: how to open excel file for edit and save back into the same file. Pin
Luc Pattyn11-Mar-10 16:42
sitebuilderLuc Pattyn11-Mar-10 16:42 
AnswerRe: how to open excel file for edit and save back into the same file. Pin
dybs13-Mar-10 16:32
dybs13-Mar-10 16:32 
Questionencoding/decoding, still cant figure it out? Pin
stephen.darling11-Mar-10 14:51
stephen.darling11-Mar-10 14:51 
AnswerRe: encoding/decoding, still cant figure it out? Pin
Dr.Walt Fair, PE11-Mar-10 16:00
professionalDr.Walt Fair, PE11-Mar-10 16:00 
GeneralRe: encoding/decoding, still cant figure it out? Pin
Rod Kemp11-Mar-10 16:08
Rod Kemp11-Mar-10 16:08 
AnswerRe: encoding/decoding, still cant figure it out? [modified] Pin
Rod Kemp11-Mar-10 16:03
Rod Kemp11-Mar-10 16:03 
Here[^] is a link on how to do binary math, have a look at the Decimal Conversion section and see if you can use this to figure out what you need to do.

Here, now try to do the reverse yourself;
//41 digit number string
string originalNumberString = "3454587632090873454498766009893432389887";

char[] numberValues = originalNumberString.ToCharArray();
int numberLength = numberValues.Length;
int originalLength = numberValues.Length;
string binaryNumber = string.Empty;

do
{
   char[] newNumberString = new char[numberLength];
   double remainderValue = 0.00;

   //Divide the string number by 2
   foreach (char numberValue in numberValues)
   {
      double valueNumber = (double.Parse(numberValue.ToString()) / 2) + remainderValue;
      remainderValue = (valueNumber % 1) * 10;

      newNumberString[originalLength - numberLength] = (valueNumber - (valueNumber % 1)).ToString().ToCharArray()[0];

      --numberLength;
   }

   //If there is a remainder the bit value is 1 else 0
   binaryNumber +=  (remainderValue > 0 ? 1 : 0);
   int offSetValue = (newNumberString[0] == '0' ? 1 : 0);

   numberValues = new char[numberValues.Length - offSetValue];
   Array.Copy(newNumberString, offSetValue, numberValues, 0, numberValues.Length);
   numberLength = numberValues.Length;
   originalLength = numberValues.Length;
} while (originalLength > 0);

//Add extra zeros to fit 8bits to a byte exactly
while (((binaryNumber.Length / 8.0) % 1) > 0)
{
   binaryNumber += "0";
}

//Reverse the order of the bits in the string so it is MSB to LSB.
char[] charArray = binaryNumber.ToCharArray();
Array.Reverse(charArray);
binaryNumber = new string(charArray);

//Convert the binaryString value to a byte array index 0 will be the MSB value to to the array reverse code above.
//If you want index 0 to be the LSB then omit the array reversing code above.
byte[] numberArray = new byte[binaryNumber.Length / 8];
System.Collections.BitArray bitArray = new System.Collections.BitArray(binaryNumber.Length);
for (int bitIndex = 0; bitIndex < binaryNumber.Length; ++bitIndex)
{
   bitArray[bitIndex] = (binaryNumber[bitIndex] == '1' ? true : false);
}
bitArray.CopyTo(numberArray, 0);

This will give you a 17 byte array or a 136 bit BitArray for a 41 digit number.
modified on Friday, March 12, 2010 2:15 AM

AnswerRe: encoding/decoding, still cant figure it out? [modified] Pin
#realJSOP12-Mar-10 1:55
professional#realJSOP12-Mar-10 1:55 
GeneralRe: encoding/decoding, still cant figure it out? Pin
Rod Kemp12-Mar-10 3:48
Rod Kemp12-Mar-10 3:48 
Questionhow can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 14:03
crisjala11-Mar-10 14:03 
AnswerRe: how can i enable back newToolStripMenuItem to true Pin
DaveyM6911-Mar-10 14:18
professionalDaveyM6911-Mar-10 14:18 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 19:27
crisjala11-Mar-10 19:27 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 20:37
crisjala11-Mar-10 20:37 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
DaveyM6912-Mar-10 3:51
professionalDaveyM6912-Mar-10 3:51 
QuestionCatch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 9:42
Matthew Klein11-Mar-10 9:42 
AnswerRe: Catch Asynchronous Exception? Pin
AspDotNetDev11-Mar-10 13:36
protectorAspDotNetDev11-Mar-10 13:36 
AnswerRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 13:46
sitebuilderLuc Pattyn11-Mar-10 13:46 
GeneralRe: Catch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 14:18
Matthew Klein11-Mar-10 14:18 
GeneralRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 14:33
sitebuilderLuc Pattyn11-Mar-10 14:33 
QuestionRemoting & Events ("Exception has been thrown by the target of an invocation.”) Pin
bluescreen7611-Mar-10 8:41
bluescreen7611-Mar-10 8:41 
AnswerRemoting & Events ("Exception has been thrown by the target of an invocation.”) - urgent! Pin
bluescreen7616-Mar-10 4:18
bluescreen7616-Mar-10 4:18 
QuestionOutlook addin integration problem with Outlook 2007 Pin
mosh_3311-Mar-10 6:52
mosh_3311-Mar-10 6:52 
QuestionSwitch versus an array of delegates Pin
PIEBALDconsult11-Mar-10 5:36
mvePIEBALDconsult11-Mar-10 5:36 
AnswerRe: Switch versus an array of delegates Pin
Saksida Bojan11-Mar-10 5:43
Saksida Bojan11-Mar-10 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.