How does bitshift work?
Mostra commenti meno recenti
bitshift(56,-1)
gives answer 28 in matlab
My understanding of this working is as follows:
the function converts 56 to binary value ie 0101 0110 and does right shift since its -1
so 0010 1011 -> 2b (hexa)
so the answer should be "2b" right?
How does this function work?
4 Commenti
Scott MacKenzie
il 4 Mag 2021
In your example, k = -1, so the shift is to the right, not the left.
Kaavya N
il 4 Mag 2021
"the function converts 56 to binary value ie 0101 0110"
You appear to have mixed up decimal and hexadecimal:
B = '01010110'; % your binary string
D = pow2(numel(B)-1:-1:0)*sscanf(B,'%1d') % decimal
D = bin2dec(B) % decimal
H = dec2hex(D) % hexadecimal
H = sprintf('%x',D) % hexadecimal
Kaavya N
il 5 Mag 2021
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Numeric Types in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
