We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Not sure what your questions is, but are you just asking how to display binary numbers? Also be careful, there isn't a thing called binary decimals, they're both different bases (base 2 and base 10).
Anyhoo, the binary numbers are the actual representation of numbers, so they're naturally stored as binary. If you want to print them out then the easiest way is to use a string, like so:
publicstaticStringprintBin(intn){Stringbin="";while(n>0){bin=Integer.toString(n%2)+bin;// store the "bits" in reverse ordern/=2;}returnbin;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Not sure what your questions is, but are you just asking how to display binary numbers? Also be careful, there isn't a thing called binary decimals, they're both different bases (base 2 and base 10). Anyhoo, the binary numbers are the actual representation of numbers, so they're naturally stored as binary. If you want to print them out then the easiest way is to use a string, like so: