Click here to Skip to main content
15,879,535 members
Home / Discussions / C#
   

C#

 
GeneralRe: Struct vs Class? (Off Topic) Pin
David C# Hobbyist.17-Feb-14 11:12
professionalDavid C# Hobbyist.17-Feb-14 11:12 
GeneralRe: Struct vs Class? (Off Topic) Pin
OriginalGriff17-Feb-14 11:24
mveOriginalGriff17-Feb-14 11:24 
GeneralRe: Struct vs Class? (Off Topic) Pin
OriginalGriff23-Feb-14 0:29
mveOriginalGriff23-Feb-14 0:29 
GeneralRe: Struct vs Class? (Off Topic) Pin
David C# Hobbyist.23-Feb-14 4:42
professionalDavid C# Hobbyist.23-Feb-14 4:42 
GeneralRe: Struct vs Class? (Off Topic) Pin
OriginalGriff23-Feb-14 4:57
mveOriginalGriff23-Feb-14 4:57 
QuestionInterface for Authorization Custom Inteface c# Winforms .net 4.0 Pin
Member 1050351416-Feb-14 12:10
Member 1050351416-Feb-14 12:10 
AnswerRe: Interface for Authorization Custom Inteface c# Winforms .net 4.0 Pin
Eddy Vluggen17-Feb-14 0:29
professionalEddy Vluggen17-Feb-14 0:29 
QuestionStrange bug when converting from binary to decimal.. Pin
Alex Reed16-Feb-14 9:54
Alex Reed16-Feb-14 9:54 
Hello all. I recently finished a homework assignment which involves creating a fully functioning calculator in c# which can also take the integers which are being displayed and convert them to binary, and then vice versa via radio controls.

My convert2decimal function isn't working correctly though. Say I input 999 into the window, it will output the correct binary value of
1111100111
But then when i click the radio button to convert that value from the text box back to decimal, instead if 999 i get 927.
Also yes i am aware that i could simply declare a variable to hold the original decimal value, but i doubt my instructor would look upon that fondly.
Here is the offending code snippet
C#
private void convert2Decimal(string value)
       {
          String binaryDigits = value;
          char []  Binary = binaryDigits.ToCharArray(); // new array filled with a binary digit for each indice, in char form. Will need to be Parsed

          long dValue = 0;                                    // int array to recieve parsed strings
          int superscript = display.Text.Length - 1;          // Value which will hold the power of 2 based on how many indices there are
          int bValue = 1;
          if (superscript > 0)
          {
               foreach (char element in Binary )
              {
                  Console.WriteLine((long)char.GetNumericValue(element));
                  if ((long)char.GetNumericValue(element) == 1)
                  {
                    Console.WriteLine(  dValue += ((long)char.GetNumericValue(element)) * bValue);     //assigns the char converted to integer to the int dValue

                  }bValue *= 2;

              }
              display.Text =""+ dValue;
          }


Even more strange behavior is that, when converting the wrong value of 927 back to binary via the binary conversion, i get the correct binary value of 927, but when i finally click the decimal conversion, it shows a value of 999...!Confused | :confused:
AnswerRe: Strange bug when converting from binary to decimal.. Pin
Richard Andrew x6416-Feb-14 11:25
professionalRichard Andrew x6416-Feb-14 11:25 
GeneralRe: Strange bug when converting from binary to decimal.. Pin
Alex Reed17-Feb-14 14:01
Alex Reed17-Feb-14 14:01 
AnswerRe: Strange bug when converting from binary to decimal.. Pin
Richard MacCutchan16-Feb-14 22:40
mveRichard MacCutchan16-Feb-14 22:40 
GeneralRe: Strange bug when converting from binary to decimal.. Pin
Richard Deeming17-Feb-14 1:54
mveRichard Deeming17-Feb-14 1:54 
GeneralRe: Strange bug when converting from binary to decimal.. Pin
Richard MacCutchan17-Feb-14 3:01
mveRichard MacCutchan17-Feb-14 3:01 
GeneralRe: Strange bug when converting from binary to decimal.. Pin
Alex Reed17-Feb-14 14:00
Alex Reed17-Feb-14 14:00 
GeneralRe: Strange bug when converting from binary to decimal.. Pin
Richard MacCutchan17-Feb-14 21:12
mveRichard MacCutchan17-Feb-14 21:12 
Questiontabcontrol OwnerDrawFixed right to left in c# Pin
Member 1059114816-Feb-14 1:39
Member 1059114816-Feb-14 1:39 
QuestionHow to Open form inside existing Tab Page Pin
Member 1059114816-Feb-14 1:36
Member 1059114816-Feb-14 1:36 
AnswerRe: How to Open form inside existing Tab Page Pin
Member 1059114816-Feb-14 8:33
Member 1059114816-Feb-14 8:33 
QuestionRe: How to Open form inside existing Tab Page Pin
Ravi Bhavnani17-Feb-14 7:54
professionalRavi Bhavnani17-Feb-14 7:54 
Questionhello sir... for com port setting for sms application in c# Pin
aawajaarughat15-Feb-14 23:18
professionalaawajaarughat15-Feb-14 23:18 
AnswerRe: hello sir... for com port setting for sms application in c# Pin
Kornfeld Eliyahu Peter15-Feb-14 23:31
professionalKornfeld Eliyahu Peter15-Feb-14 23:31 
AnswerRe: hello sir... for com port setting for sms application in c# Pin
OriginalGriff15-Feb-14 23:32
mveOriginalGriff15-Feb-14 23:32 
QuestionTrying to make a converter Pin
daddy35615-Feb-14 14:01
daddy35615-Feb-14 14:01 
AnswerRe: Trying to make a converter Pin
Richard Andrew x6415-Feb-14 17:26
professionalRichard Andrew x6415-Feb-14 17:26 
GeneralRe: Trying to make a converter Pin
Mycroft Holmes15-Feb-14 20:41
professionalMycroft Holmes15-Feb-14 20:41 

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.