{"id":17197,"date":"2021-08-26T10:42:58","date_gmt":"2021-08-26T05:12:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=17197"},"modified":"2021-11-22T18:37:10","modified_gmt":"2021-11-22T13:07:10","slug":"python-program-to-check-a-binary-number-is-divisible-by-a-number-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-a-binary-number-is-divisible-by-a-number-n\/","title":{"rendered":"Python Program to Check a Binary Number is Divisible by a Number N"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Pick a Random Card<\/a>
\nBinary Number:<\/strong><\/p>\n

A binary number is a number expressed in the base 2 numeral system, which employs only the symbols 0 and 1.<\/p>\n

Conversion from binary to decimal:<\/strong><\/p>\n

binary number = 1010<\/p>\n

decimal number = int(str(binary number),2)<\/strong><\/p>\n

Given a binary number, and the task is to check if the binary number is divisible by a given number N.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given binary number = 1100\r\nGiven number = 4<\/pre>\n

Output:<\/strong><\/p>\n

The given binary number is divisible by{ 4 }<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given binary number = 1000\r\nGiven number = 2<\/pre>\n

Output:<\/strong><\/p>\n

The given binary number is divisible by{ 2 }<\/pre>\n

Program to Check a Binary Number is Divisible by a number N.<\/h2>\n

Below are the ways to check if the given binary number is divisible by a given number N.<\/p>\n