VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-number-divisible-8-using-bitwise-operators/

⇱ Divisibility by 8 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Divisibility by 8

Last Updated : 21 Apr, 2026


Given a string s representing a non-negative decimal number, determine whether the number is divisible by 8. Return true if it is divisible by 8, otherwise return false.

Examples:  

Input: s = "16"
Output: true
Explanation: The given number is divisible by 8. So the answer is true.

Input: s = "54141111648421214584416464555"
Output: false
Explanation: Given Number is not divisible by 8. So the answer for this is false.

Using Mathematical Divisibility Rule - O(1) Time and O(1) Space

A number is divisible by 8 if its last three digits are divisible by 8. So, check only the last three digits when the string length is greater than 3; otherwise, check the whole number. 


Output
1
Comment