15 views (last 30 days)

Never mind I messed up.

n=sym('94315998522576010519588224930693232398146802027362761139521');

a=7;

i=1;%this is a counter that starts from 1.

for i=1:inf

remainder=mod(n-1,2^i);

if remainder~=0

break

end

end

r=i-1%r takes the second last value of i because 2 raised to the last value is not divisible by n-1

s=rdivide(n-1,2^r)%this is the integer we get after n-1 is divided by the 2^(i-1)

James Tursa
on 9 Dec 2019

Edited: James Tursa
on 9 Dec 2019

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/495723-highest-power-of-2-that-divides-n#comment_776163

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/495723-highest-power-of-2-that-divides-n#comment_776163

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/495723-highest-power-of-2-that-divides-n#comment_776225

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/495723-highest-power-of-2-that-divides-n#comment_776225

Sign in to comment.