필터 지우기
필터 지우기

Binary data processing in an algorithm

조회 수: 1 (최근 30일)
Amanpreet Singh
Amanpreet Singh 2015년 3월 30일
댓글: Amanpreet Singh 2015년 3월 31일
Hi I am writing a program that will operate only on binary numbers. Are there any right or left shift operation functions? Is there any way or function or I ll need to create an algorithm for their conversion? Will be very grateful.

채택된 답변

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 30일
Hi
Does bitshift help you?
a = intmax('uint8');
s1 = 'Initial uint8 value %5d is %08s in binary\n';
s2 = 'Shifted uint8 value %5d is %08s in binary\n';
fprintf(s1,a,dec2bin(a))
for i = 1:8
a = bitshift(a,1);
fprintf(s2,a,dec2bin(a))
end
Initial uint8 value 255 is 11111111 in binary
Shifted uint8 value 254 is 11111110 in binary
Shifted uint8 value 252 is 11111100 in binary
Shifted uint8 value 248 is 11111000 in binary
Shifted uint8 value 240 is 11110000 in binary
Shifted uint8 value 224 is 11100000 in binary
Shifted uint8 value 192 is 11000000 in binary
Shifted uint8 value 128 is 10000000 in binary
Shifted uint8 value 0 is 00000000 in binary
Regards
  댓글 수: 1
Amanpreet Singh
Amanpreet Singh 2015년 3월 31일
Hi Thanks Sir for your reply. Regards

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by