-
Notifications
You must be signed in to change notification settings - Fork 20.3k
conversion binary to hexadecimal #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
conversion binary to hexadecimal
* @return The hexadecimal number | ||
*/ | ||
|
||
public String binToHex(int binary) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The binary number may have 32bits or 64bits, so it's unsuitable to use int
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
resolving comment
public void testBinaryToHexadecimal(){ | ||
BinaryToHexadecimal binaryToHexadecimal = new BinaryToHexadecimal(); | ||
Assert.assertEquals("Incorrect Conversion", "2A", binaryToHexadecimal.binToHex(101010)); | ||
Assert.assertEquals("Incorrect Conversion", "24", binaryToHexadecimal.binToHex(100100)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the test case 1010101010101010101010101010101010101010101010101010101010101010101010100001
(64 bits)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, i had to use BigInteger to resolve that case you commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arodriguez33 Thanks for your changes :)
conversion binary to hexadecimal