Surprised => indulgence => Calm => Lost => Panic =>Calm

算法-每天一道题(28)-405. Convert a Number to Hexadecimal-进制转换

算法 admin 962℃ 0评论

Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.

Note:

1All letters in hexadecimal (a-f) must be in lowercase.2The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character ‘0’; otherwise, the first character in the hexadecimal string will not be the zero character.3The given number is guaranteed to fit within the range of a 32-bit signed integer.4You must not use any method provided by the library which converts/formats the number to hex directly.

Example 1:

Input:

26

Output:

“1a”

Example 2:

Input:

-1

Output:

“ffffffff”

Go语言

转载请注明:Imekaku-Blog » 算法-每天一道题(28)-405. Convert a Number to Hexadecimal-进制转换

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址