Madz Posted July 30, 2003 Posted July 30, 2003 Can any one tell me some method throgh which i can convert a deciaml to Binary Such as if i want to convert 256 to 010101 format what whould be the keywork of C#. Quote The one and only Dr. Madz eee-m@il
JABE Posted July 30, 2003 Posted July 30, 2003 I'm not aware of any methods that can easily fulfill your requirements (similar to javascript's int.toString(2) functionality) but here's a little C# function that can get you started: private string ToBinaryString(int num, int stringLength) { System.Text.StringBuilder sb = new System.Text.StringBuilder(stringLength); for (int k = 0; k < stringLength; k++){ sb.Append((num & (int)Math.Pow(2, k)) > 0 ? "1" : "0"); } return sb.ToString(); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.