How can I convert BitArray to single int?

后端 未结 4 909
借酒劲吻你
借酒劲吻你 2020-11-27 05:07

How can I convert BitArray to a single int?

4条回答
  •  庸人自扰
    2020-11-27 05:42

    Reffering to this post (#43935747). A value X is short tpe whic I set two bits (6 and 10) like below: short X=1;

            var result = X;
            var bitsToSet = new [ ] { 5,9 };
            foreach ( var bitToSet in bitsToSet )
                {
                result+=( short ) Math.Pow ( 2,bitToSet );
                }
            string binary = Convert.ToString ( result,2 );
    

    Now I would like to read the specific all bits from Value X and put it in to an array or a bit type like bool Val1= bit1, bool Val2=bit2....

    I am a newbie and I think it is pretty simple for you guyes..

提交回复
热议问题