필터 지우기
필터 지우기

How to change a bit from 0 to 1.

조회 수: 6 (최근 30일)
barath manoharan
barath manoharan 2023년 2월 15일
답변: Steven Lord 2023년 2월 15일
iam having 5 decimal numbers , i have converted this 5 decimal nos to binary numbers to perform some mathematical operations.
A consists of five decimal numbers and B consists of A's corresponding binary representation. Now each element has to be compared against the remaining elements. first element and last element differs by one bit so the expected output is 10111 similarly 2nd element and last element differs by 1 bit so the expected output is 10111. the remaining 2 elements cannot be merged because they have more than 1 dissimilar bit when compared against remaining elements. The expected output is 10111,1100,1011. Thank you in advance.
For example:
A = [7;19;12;11;23]
B = [00111;10011;01100;01011;10111]
Expected Output :
C = [10111;01100;01011]
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 2월 15일
So you want to compare 1st and nth element, 2nd and n-1 th element and 3rd and n-2 th element and so on?
Jan
Jan 2023년 2월 15일
편집: Jan 2023년 2월 15일
The same problem occurred already in the forum. "B = [00111;10011;01100;01011;10111]" is not a binary array. "00111" is the decimal number onehundreteleven.
So please explain, in which format the values are really represented.
If you really use decimal numbers to represent binary values, this is a surprisingly bad idea, which impedes easy solutions.

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

답변 (1개)

Steven Lord
Steven Lord 2023년 2월 15일
A = [7;19;12;11;23]
A = 5×1
7 19 12 11 23
B = bitset(A, 5)
B = 5×1
23 19 28 27 23
binA = dec2bin(A, 5)
binA = 5×5 char array
'00111' '10011' '01100' '01011' '10111'
binB = dec2bin(B, 5)
binB = 5×5 char array
'10111' '10011' '11100' '11011' '10111'

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by