Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created January 13, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M-ZubairAhmed/faf276583b4a11a3c5045d7656329726 to your computer and use it in GitHub Desktop.
Save M-ZubairAhmed/faf276583b4a11a3c5045d7656329726 to your computer and use it in GitHub Desktop.
Conversion of a Binary Number to Decimal Number
public static int binaryToDecimal (int binaryNumber){
int digitIndex;
int decimalNum = 0;
int powerIndex = 0;
while(( binaryNumber != 0) && ( binaryNumber >0)){
digitIndex = binaryNumber % 10;
decimalNum = decimalNum + (int)(Math.pow(2,powerIndex) * digitIndex);
binaryNumber = binaryNumber / 10;
powerIndex++;
}
return decimalNum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment