I posted an answer to this question, but I cannot see the answer in my
newsreader... so I'll post another answer. If you get both: sorry!
Binary math: each binary digit is worth two times more than the position
below it (just like decimal math). So, to more one bit, you multiply by 2.
To move 8 bits, you multiply by 256 (or simply shift the bits over 8
positions).
So, if you take the byte that represents the 'big end' of the number, put it
into a container that is 16 bits wide, it will be placed in the lower 8
bits. That's wrong... it needs to be in the upper 8 bits... so shift it out
of the way. The lower 8 bits will be left containing zeros (trust me). You
can either add the lower 8 bits in, or use the OR operator. Either way, you
get a single, 16 bit number that contains all the bits in all the right
places.
Does that explain it?
--- Nick
"Sunit Joshi" <sj****@ingr.com> wrote in message
news:8f**************************@posting.google.c om...
Thanks for all the replies...could someone please explain to me how
they arrived at this..??
thanks
Sunit
"Stoitcho Goutsev \(100\) [C# MVP]" <10*@100.com> wrote in message
news:<uD**************@TK2MSFTNGP10.phx.gbl>...
Hi Sunit,
First use String.Split method to get each parts of the string.
Then using int.Parse create the numerical representation of these parts.
and then depending on the order of which they come calculate the value
string a = "171,205";
string []parts = a.Split(',');
int part1 = int.Parse(parts[0]);
int part2 = int.Parse(parts[1]);
int res = part1*256 + part2;
//if the most segnificant bits are in part2 then part2*256 + part1;
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Sunit Joshi" <sj****@ingr.com> wrote in message
news:8f**************************@posting.google.c om... I have a 16-bit port no. This address information is broken into 8-bit
fields and the value of each field is transmitted as a decimal number
(in character string representation , eg: "177,147")
How do I get the port no from this..??
thanks
Sunit