صفحه دوم

ASCII to binary

این یه راه برای تبدیل 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;

       


گزارش تخلف
بعدی