ok, well i don't know how much this will help you, but i had to do basically the same thing for my java class near the start of the year.
C# and Java have a sort of simliar syntax, here is the code (ignore the fact that there is no main method, we put it into a graphical interface which called all of the things needed.
Code:
import java.lang.StringBuffer;
public class Numconverter
{
public String bin = "";
public String hex = "";
public String oct = "";
public StringBuffer kb;
public double dnum, bnum, hnum, onum;
public void setDecimal(double number)
{
dnum = number;
}
public void setOct(String number)
{
oct = number;
kb = new StringBuffer(oct);
int length = kb.length();
for(length = length; length != 0; length--)
{
char num = kb.charAt(length-1);
if(num != '0' && num != '1' && num != '2' && num != '3' && num != '4' && num != '5' && num != '6' && num != '7')
{
oct = "ERROR";
}
}
}
public void setHex(String number)
{
hex = number;
kb = new StringBuffer(hex);
int length = kb.length();
for(length = length; length != 0; length--)
{
char num = kb.charAt(length-1);
if(num != '0' && num != '1' && num != '2' && num != '3' && num !='4' && num !='5' && num !='6' && num !='7' && num !='8' && num !='9' && num !='A' && num !='B' && num !='C' && num != 'D' && num !='E' && num !='F')
{
hex = "ERROR";
}
}
}
public void setBin(String number)
{
//long bnum2 = (long)number;
//bin = Long.toString(bnum2);
bin = number;
kb = new StringBuffer(bin);
int length = kb.length();
for(length = length; length != 0; length--)
{
char num = kb.charAt(length-1);
if(num != '1' && num != '0')
{
bin = "ERROR";
}
}
}
public String getDecfromBin()
{
double z = 0;
int c = 0;
int m = 0;
int x = 1;
int length = kb.length();
int[] thearray = new int[length];
if(bin != "ERROR")
{
for(x = 0; x != length; x++)
{
String norg = String.valueOf(kb.charAt(x));
int go = Integer.valueOf(norg);
thearray[x] = go;
}
for(z = length; z != 0; z--)
{
int a = thearray[m];
double pow = Math.pow(2.0, z-1);
double b = a*pow;
c += b;
m++;
}
}
else
{
return(bin);
}
bin = Integer.toString(c);
return(bin);
}
public String getBinaryfromDec()
{
bnum = dnum;
int g = (int)dnum;
int y = 0;
int[] binnum = new int[g];
for(int x = 1; bnum != 0; x++)
{
binnum[x-1] = (int)(bnum % 2);
if((int)bnum/2 != 0)
{
bnum = bnum/2;
}
else
{
bnum=0;
}
y = y + 1;
}
for(int counter = y; counter != 0; counter--)
{
bin += binnum[counter-1];
}
return(bin);
}
public String getHexfromDec()
{
hnum = dnum;
int g = (int)dnum;
int y = 0;
int[] hexnum = new int[g];
for(int x = 1; hnum != 0; x++)
{
hexnum[x-1] = (int)(hnum%16);
if((int)hnum/16 != 0)
{
hnum = hnum/16;
}
else
{
hnum = 0;
}
y = y +1;
}
for(int counter = y; counter != 0; counter--)
{
if(hexnum[counter-1] == 10)
{
hex += "A";
}
else if(hexnum[counter-1] == 11 )
{
hex += "B";
}
else if(hexnum[counter-1] == 12 )
{
hex += "C";
}
else if(hexnum[counter-1] == 13)
{
hex += "D";
}
else if(hexnum[counter-1] == 14)
{
hex += "E";
}
else if(hexnum[counter-1] == 15)
{
hex += "F";
}
else
{
hex += hexnum[counter-1];
}
}
return(hex);
}
public String getDecfromHex()
{
double z = 0;
int c = 0;
int m = 0;
int x = 1;
int go = 0;
int length = kb.length();
int[] thearray = new int[length];
if(hex != "ERROR")
{
for(x = 0; x != length; x++)
{
char norg = kb.charAt(x);
if(norg == 'A')
{
go = 10;
}
else if(norg == 'B')
{
go = 11;
}
else if(norg == 'C')
{
go = 12;
}
else if(norg == 'D')
{
go = 13;
}
else if(norg == 'E')
{
go = 14;
}
else if(norg == 'F')
{
go = 15;
}
else
{
String norg2 = String.valueOf(kb.charAt(x));
go = Integer.valueOf(norg2);
}
thearray[x] = go;
}
for(z = length; z != 0; z--)
{
int a = thearray[m];
double pow = Math.pow(16.0, z-1);
double b = a*pow;
c += b;
m++;
}
}
else
{
return(hex);
}
hex = Integer.toString(c);
return(hex);
}
public String getOctfromDec()
{
onum = dnum;
int g = (int)dnum;
int y = 0;
int[] octnum = new int[g];
for(int x = 1; onum != 0; x++)
{
octnum[x-1] = (int)(onum%8);
if((int)onum/8 != 0)
{
onum = onum/8;
}
else
{
onum = 0;
}
y = y +1;
}
for(int counter = y; counter != 0; counter--)
{
oct += octnum[counter-1];
}
return(oct);
}
public String getDecfromOct()
{
double z = 0;
int c = 0;
int m = 0;
int x = 1;
int length = kb.length();
int[] thearray = new int[length];
if(oct != "ERROR")
{
for(x = 0; x != length; x++)
{
String norg = String.valueOf(kb.charAt(x));
int go = Integer.valueOf(norg);
thearray[x] = go;
}
for(z = length; z != 0; z--)
{
int a = thearray[m];
double pow = Math.pow(8.0, z-1);
double b = a*pow;
c += b;
m++;
}
}
else
{
return(oct);
}
oct = Integer.toString(c);
return(oct);
}
}
Ignore how shitty and repetitive the code is please, this was done at the START of the year. Also, it converts it to a string due to the graphical interface used for it.