String to binary method:

 public static string StringToBinary(string data)
{
StringBuilder sb = new StringBuilder(); foreach (char c in data.ToCharArray())
{
sb.Append(Convert.ToString(c, ).PadLeft(, ''));
}
return sb.ToString();
}

Binary to string method:

 public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>(); for (int i = ; i < data.Length; i += )
{
byteList.Add(Convert.ToByte(data.Substring(i, ), ));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}

Convert string to binary and binary to string in C#的更多相关文章

  1. How to convert a byte to its binary string representation

    How to convert a byte to its binary string representation For example, the bits in a byte B are 1000 ...

  2. spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

    在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...

  3. Write a program to convert decimal to 32-bit unsigned binary.

    Write a program to convert decimal to 32-bit unsigned binary. Write a program to convert a 32-bit un ...

  4. 解决 'Could not convert variant of type (NULL) into type (String)

    写存储过程中有不允许为空的字段,在客户端转化取数时显示 Could not convert variant of type (NULL) into type (String) 可以在存储过程中使用is ...

  5. 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';

    后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...

  6. Java 异常 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'

    查询时发送给服务器的日期的字符串格式:yyyy-MM-dd HH:mm:ss 服务器接收到日期的字符串之后,向 MySQL 数据库发起查询时,因为没有指定日期时间格式,导致字符串数据不能正确地转换为日 ...

  7. [转] 请别再拿“String s = new String("xyz");创建了多少个String实例”来面试了吧

    这帖是用来回复高级语言虚拟机圈子里的一个问题,一道Java笔试题的. 本来因为见得太多已经吐槽无力,但这次实在忍不住了就又爆发了一把.写得太长干脆单独开了一帖. 顺带广告:对JVM感兴趣的同学们同志们 ...

  8. String的内存模型,为什么String被设计成不可变的

    String是Java中最常用的类,是不可变的(Immutable), 那么String是如何实现Immutable呢,String为什么要设计成不可变呢? 前言 关于String,收集一波基础,来源 ...

  9. C++读写TXT文件中的string或者int型数据以及string流的用法

    对文件的读写操作是我们在做项目时经常用到的,在网上看了很多博客,结合自身的项目经验总结了一下,因此写了这篇博客,有些地方可能直接从别的博客中复制过来,但是都会注明出处. 一.文件的输入输出 fstre ...

随机推荐

  1. mem_fun 例子

    // functional_mem_fun.cpp // compile with: /EHsc #include <vector> #include <functional> ...

  2. 重构第2天:方法搬移(Move Method)

    现在就重构来说是非常普通的,虽然我们经常会漏掉或忽略一些需要重构的地方.方法搬移,正如所定义的那样,把方法搬移到更适合他的位置.让我们看看下面这一段重构前的代码: 理解:方法搬移,正如所定义的那样,把 ...

  3. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  4. 判断JavaScript对象为null或者属性为空

    http://blog.csdn.net/yiluoak_47/article/details/7766760 首先说下null与undefined区别: 对已声明但未初始化的和未声明的变量执行typ ...

  5. [原]Android打包之跨平台打包

    Android自动打包流程详细图: 在前面一些博客我们知道了如何通过命令行打包,如何通过Eclipse打包,如何通过编写shell脚本来进行打包,但是这些都不能很好的跨平台进行打包. 因Python本 ...

  6. 当应用程序不是以 UserInteractive 模式运行时显示模式对话框或窗体是无效操作

    在Web程序中引用了WinForm的类库引起了 主要是为了在web程序中使用Message.Show()以及SaveFileDialog类,能web程序中引用了WinForm类库 在Visual St ...

  7. JAVA和C# 3DES加密解密

    最近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题, 下面分享一下, 这里的KEY采用Base64编码,便用分发,因为Java的B ...

  8. HDU4550+贪心

    /* 贪心 先挑出最小的Mm,然后在Mm左侧的按情况考虑,右侧的按顺序排列. */ #include<stdio.h> #include<string.h> #include& ...

  9. Asp.Net(C#)自动执行计划任务的程序实例分析

    在业务复杂的应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件等,我们称之为计划任务.实现计划任务的方法也有很多,可以采用SQ ...

  10. DDD:一个朋友对领域驱动的小结

    首先我在一家老板有点关系的小软件公司带领一帮工作一两年的程序员做项目,这里要特别强调的是做项目(差不多是外包,只不过客户群体比较固定),项目就是今天项目A是这个逻辑,明天项目B是那个逻辑,两者之间的业 ...