I am trying to make a little program, where i can type in an IPv4 address and a SubMask address.
Works fine...
Then I will make an AND, so I can see what SubNetwork the IPv4 address is from, in (binary form)... and i can't get it to work, can someone help..
Here im trying to convert the bitwise string to an Int, so i can make and AND, but my variabels iSIDs and iSIDr (int datatype) dont get a value..
The variabels subresult and result are decimal IPv4 convertet address in 32 binary-form so BitWise strings...
string SIDsubresult = subresult;
SIDsubresult = SIDsubresult.Replace(".", "");
string SIDresult = result;
SIDresult = SIDresult.Replace(".", "");
int iSIDs = Convert.ToInt32(SIDsubresult);
int iSIDr = Convert.ToInt32(SIDresult);
Console.Write(iSIDr & iSIDs);
EDIT/UPDATE
Just so all have the code before the code i started writing.. My code before then AND code is here
var split = (from p in ipv4add.Split('.') select int.Parse(p)).ToArray();
string result = string.Format("{0}.{1}.{2}.{3}",
Convert.ToString(split[0], 2).PadLeft(8, '0'),
Convert.ToString(split[1], 2).PadLeft(8, '0'),
Convert.ToString(split[2], 2).PadLeft(8, '0'),
Convert.ToString(split[3], 2).PadLeft(8, '0'));
var subsplit = (from s in subnetmaske.Split('.') select int.Parse(s)).ToArray();
string subresult = string.Format("{0}.{1}.{2}.{3}",
Convert.ToString(subsplit[0], 2).PadLeft(8, '0'),
Convert.ToString(subsplit[1], 2).PadLeft(8, '0'),
Convert.ToString(subsplit[2], 2).PadLeft(8, '0'),
Convert.ToString(subsplit[3], 2).PadLeft(8, '0'));
string SIDsubresult = subresult;
SIDsubresult = SIDsubresult.Replace(".", "");
string SIDresult = result;
SIDresult = SIDresult.Replace(".", "");
int iSIDs = Convert.ToInt32(SIDsubresult);
int iSIDr = Convert.ToInt32(SIDresult);
Console.Write(iSIDr & iSIDs);