aboutsummaryrefslogtreecommitdiff
path: root/other/num_to_hex_binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/num_to_hex_binary.cpp')
-rw-r--r--other/num_to_hex_binary.cpp55
1 files changed, 0 insertions, 55 deletions
diff --git a/other/num_to_hex_binary.cpp b/other/num_to_hex_binary.cpp
deleted file mode 100644
index 81470fd..0000000
--- a/other/num_to_hex_binary.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "leetcode.h"
-#include <string>
-
-/*
- * given integer 'num', return string representing hexidecimal value.
- * for negative numbers, use two's complement method
- */
-
-class Solution {
-public:
- string toHex(int num) {
- string ans;
- while (num) {
- int rem = num % 16;
- if (rem > 9)
- switch (rem) {
- case 10:
- ans = 'a' + ans;
- break;
- case 11:
- ans = 'b' + ans;
- break;
- case 12:
- ans = 'c' + ans;
- break;
- case 13:
- ans = 'd' + ans;
- break;
- case 14:
- ans = 'e' + ans;
- break;
- case 15:
- ans = 'f' + ans;
- break;
- }
- else
- ans = char(rem + 48) + ans;
- num /= 16;
- }
- return ans;
- }
- int toBinary(int num) {
- int ans = 0;
- return ans;
- }
-};
-
-int main() {
- Solution obj;
- // obj.toHex(26);
- cout << obj.toHex(26) << endl; // expect: "1a"
- cout << obj.toHex(-1) << endl; // expect: "fffffff"
- cout << obj.toBinary(26) << endl; // expect: 11010
- cout << obj.toBinary(-1) << endl; // expect:
-}