Breaking a binary value into single bits

I am wanting to break up a binary value into a row of single bits to work with (i.e. 1110101101 into ten different, single column values 1, 1, 1, 0, 1, 0, 1, 1, 0, 1). I am trying to take a text file's binary value and disperse it into an array of binary values by replacing the least significant bit of the array values with the values from the broken up binary value.

답변 (1개)

Image Analyst
Image Analyst 2015년 5월 10일

2 개 추천

The binary value is already a string, right? If not, do this:
sBinary = dec2bin(941) % returns sBinary = '1110101101' string.
Then do this to get an integer array with just the 0 or 1 bit in its own element:
individualBits = sBinary - '0'

댓글 수: 3

Tyler Burk
Tyler Burk 2015년 5월 10일
Thank you! Could you also help me with the next problem I have then? I have an array of binary values [1010,0010,0110,1101,1011,1110,1111,1101,1101,1000] and I want to replace the least significant bits of each of those values with the individualBits array [1,1,1,0,1,0,1,1,0,1] respectively.
It should yield [1011,0011,0111,1100,1011,1110,1111,1101,1100,1001]
Please open a new thread for a new question.
Consider that there is no difference between the "binary values" [1010,0010] and [10100010], because both are represented by the string '10100010'. So please post exactly what kind of input you have: which class and size?
BinValue = ['1010','0010','0110','1101','1011']
BinValue(4:4:end) = '1'
V = [1 0 1 0;0 0 1 0;0 1 1 0;1 1 0 1;1 0 1 1;1 1 1 0;1 1 1 1;1 1 0 1;1 1 0 1;1 0 0 0];
v(:,end) = [1,1,1,0,1,0,1,1,0,1];

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2015년 5월 10일

댓글:

2015년 5월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by