将(0/​​1)字符串加载到位数组中 [英] Load a (0/1) string into a bit array

查看:57
本文介绍了将(0/​​1)字符串加载到位数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将"10101011101010"之类的字符串直接加载到新的位数组中,最聪明的方法是什么?(不是字节数组)

What is the smartest way to load a string like "10101011101010" directly into a new bit array? (not a byte array)

(这些位应保持与列表中相同的顺序.)

(The bits should remain in the same order as in the list.)

推荐答案

您可以使用LINQ:

var res = new BitArray(str.Select(c => c == '1').ToArray());

这篇关于将(0/​​1)字符串加载到位数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆