|
-
July 12th, 2009, 08:06 AM
#3
Re: Convert.ToString: sbyte oddity
There's no method Convert.ToString (sbyte, int). The closest one is Convert.ToString (Int16, int) as an Int16 is the smallest datatype which can fit an sbyte. So what happens is that the (Int16, int) overload is chosen when you pass an (sbyte, int). That's why you see 16 bits of output. If you want just the bits, cast the sbyte to byte first, so you choose the (byte, int) overload:
Code:
sbyte val = 5;
Convert.ToString ((byte) val, 2);
That should give the correct answer.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|