How to get quotient value after division without round off?
Show older comments
I want to get quotient (only integer value) after division of two numbers without rounding off.
n1 = I1(i,j) +1;
for k1= 0:7
l1(8-k1) = rem(n1,2);
n1 = fix(n1/2);
end
when n1 = 157 in first line :
then in fourth line after dividing by 2 , n1 is taking 79 (157/2 = 78.5) value
but i want n1 to take 78 value.
2 Comments
Khushboo Singla
on 19 Jun 2021
dpb
on 19 Jun 2021
>> n1=157;
>> fix(n1/2)
ans =
78
>>
You've done something else you've not told us about first...like an intermediate store with a rounding operation, maybe.
Even in your code;
>> n1=157;for k1= 0:7
l1(8-k1) = rem(n1,2);
n1 = fix(n1/2)
end
n1 =
78
n1 =
39
n1 =
19
n1 =
9
n1 =
4
n1 =
2
n1 =
1
n1 =
0
>>
Accepted Answer
More Answers (1)
If one or both of the numbers are stored as an integer type you could use the idivide function.
idivide(int16(157),2)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!