leetcode 405. Convert a Number to Hexadecimal 十进制转化十六进制
来源:互联网 发布:java怎么调试错误 编辑:程序博客网 时间:2024/05/02 05:59
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.
Note:
All letters in hexadecimal (a-f) must be in lowercase.
The 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.
The given number is guaranteed to fit within the range of a 32-bit signed integer.
You 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”
这道题题意十分简单,就是做一个十六进制的转换,对于C++直接取值转换即可
代码如下:
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <climits>#include <algorithm>#include <sstream>#include <bitset>using namespace std;class Solution {public: string toHex(int num) { if (num == 0) return "0"; const string HEX = "0123456789abcdef"; string result; int count = 0; while (num!=0 && count < 8) { result = HEX[(num & 0xf)] + result; num >>= 4; count++; } return result; }};
- leetcode 405. Convert a Number to Hexadecimal 十进制转化十六进制
- leetcode 405. Convert a Number to Hexadecimal(十进制转十六进制>>>)
- [LeetCode]405. Convert a Number to Hexadecimal(32位有符号整数转化为十六进制)
- Leetcode405. Convert a Number to Hexadecimal十进制转十六进制
- LeetCode 405. Convert a Number to Hexadecimal
- [LeetCode]--405. Convert a Number to Hexadecimal
- [leetcode]405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- leetcode 405. Convert a Number to Hexadecimal
- leetcode 405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- 【LeetCode】 405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- [LeetCode]405. Convert a Number to Hexadecimal
- Leetcode-405. Convert a Number to Hexadecimal
- LeetCode-405. Convert a Number to Hexadecimal
- 【Leetcode】405. Convert a Number to Hexadecimal
- Android.Application
- Navicat连接阿里云Ubuntu的mysql
- 欢迎使用CSDN-markdown编辑器
- 写给立志做码农的大学生
- java8 新特性
- leetcode 405. Convert a Number to Hexadecimal 十进制转化十六进制
- nginx 公用一个tomcat,配置不同的域名
- 女博士养成记2——挣钱养梦
- Linux进程间通信(1)
- 【UE4 全局光照明】虚幻引擎学习之路:渲染模块之全局光照明 by UWA侑虎科技
- 正向代理与反向代理
- 通过什么可以让SQL语句更加快速的获得结果
- C语言学习的第六天(续)
- java实时向zip中写excel文件并通过浏览器实现下载