• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 10 رای - 3 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: ASCII to binary
حالت موضوعی
#1

این یه راه برای تبدیل ASCII to binary
کد:
public string ToBinary(string str)

        {

            string converted = string.Empty;

            byte[] byteArray = GetByteArray(str);



            //create a memory stream

            MemoryStream stream = new MemoryStream();



            //create BinaryWriter based on our MemoryStream

            BinaryWriter writer = new BinaryWriter(stream);



            //convert to binary

            try

            {

                writer.Write(byteArray);

            }

            catch (Exception ex)

            {

                return ex.Message;

            }



            for (int i = 0; i < byteArray.Length; i++)

            {

                for (int j = 0; j < 8; j++)

                {

                    converted += (byteArray[i] & 0x80) > 0 ? "1" : "0";

                    byteArray[i] <<= 1;

                }

            }



            return converted;

        }
 
پاسخ
  


پرش به انجمن:


Browsing: 1 مهمان