Use of oprators div, mod and <<

Status
Not open for further replies.

aduri

New Member
Can you explain me the use of these operator div, mod and <<?
My problem is: from a number of six figures: (for example) 123456 I'd like to capture
the 6 the 5 and the others until the 1.
I have tried 123456/10 and I should have obtained the module with a rest 6 and
after that I should have shifted on the left and repeat all over again but it didn't work.
I use Mikrobasic.
The code that I have implemented is the following:

dim count as longint
count=123456
countmod1=(count div 10) mod 10
<<count
.......

Thanks
Bye
 
I'm not sure quite what you're trying to do.
123456 divided by 10 would be 12345.6, and since you're using an integer your answer would be 12345. that number, modulo 10, would be the remainder of 12345 again divided by 10, which should be 5. If you're trying to get the 6 first, you want to do just the modulo, not the division. If you don't understand this then you should go search around the web to learn what modulo is.

And it doesn't seem like you understand the << operator either. a left shift is done in BINARY, not in decimal. 12345 in binary is 0b11000000111001, shift that left and you get 0b110000001110010, which is 24690 in decimal. If you are trying to 'shift left' in decimal, just multiply by 10... but if you're planning to just grab the next digit afterward, I don't see too much reason to do this before continuing...
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…