Check integer for 0 on last digit

Hi

Is there a way to check if an integer say 123456 has a 0 on the last digit using bitwise operators only and not string conversions?

1
2
3
4

123450 //This has a 0 for the last digit
123456 //This does not have a 0 for the last digit 


I'm attempting a problem but the conversion from int to string is a huge bottleneck in a loop.

Thanks
Last edited on
You could use bitwise operations to check for a binary zero, or even a hexadecimal or octal zero. But if it's everyday decimal digits you are interested in, then the modulus operator % is probably the simplest method.
 
123450 % 10 == 0
 
123456 % 10 != 0


Wow I thought it required something complex , although I did think about the modulus operator i didn't see how it could do that. Thanks!
Topic archived. No new replies allowed.