Skip to content

conversion binary to hexadecimal#694

Merged
yanglbme merged 5 commits intoTheAlgorithms:Developmentfrom
arodriguez33:Development
Jan 30, 2019
Merged

conversion binary to hexadecimal#694
yanglbme merged 5 commits intoTheAlgorithms:Developmentfrom
arodriguez33:Development

Conversation

@arodriguez33
Copy link

conversion binary to hexadecimal

conversion binary to hexadecimal
* @return The hexadecimal number
*/

public String binToHex(int binary) {
Copy link
Member

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.

Copy link
Author

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));
Copy link
Member

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)

Copy link
Author

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.

Copy link
Member

@yanglbme yanglbme left a 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 :)

@yanglbme yanglbme merged commit fe277cf into TheAlgorithms:Development Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants