Bit setting a binary number

Is there any way to set specific bits in a binary number in Matlab.
I'm currently converting a number into a binary string using the dec2bin function, I then want to change the lower 6 bits.
ie
dec2bin(3124)
ans = 110000110100
I need to set the lower 6 bits to be 100000, resulting in:
ans = 110000100000
Is this possible?
Thanks, Ben

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 7월 10일

0 개 추천

a = dec2bin(3124)
a(end - (5:-1:0)) = '100000'

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by