Check the divisibility of Hexadecimal numbers | C # implementation of the approach ; Function that returns true if s is divisible by m ; Map to map characters to real values ; To store the remainder at any stage ; Find the remainder ; Check the value of remainder ; Driver code
using System ; using System . Collections . Generic ; class GFG { static char [ ] CHARS = "0123456789ABCDEF " . ToCharArray ( ) ; static int DIGITS = 16 ; static bool isDivisible ( String s , int m ) { Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < DIGITS ; i ++ ) { if ( mp . ContainsKey ( CHARS [ i ] ) ) mp [ CHARS [ i ] ] = i ; else mp . Add ( CHARS [ i ] , i ) ; } int r = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { r = ( r * 16 + mp [ s [ i ] ] ) % m ; } if ( r == 0 ) return true ; return false ; } public static void Main ( String [ ] args ) { String s = "10" ; int m = 3 ; if ( isDivisible ( s , m ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }