Skip to content

Instantly share code, notes, and snippets.

@jmkim
Created September 27, 2025 03:49
Show Gist options
  • Save jmkim/9c789e3cd86d2d15afe967bc1b9bdc1b to your computer and use it in GitHub Desktop.
Save jmkim/9c789e3cd86d2d15afe967bc1b9bdc1b to your computer and use it in GitHub Desktop.
char a2i[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
// in_base진수에서 int형(10진수)으로 변환
// in_base가 10진수 이상일 경우 대문자만 지원(A, B, C, ...)
int stoi(string input, int in_base) {
int number = 0;
for(char ch : input) {
number *= in_base;
number += ch - ((ch <= '9') ? '0' : 'A' - 10);
}
return number;
}
// int형(10진수)에서 out_base진수로 변환
// in_base가 10진수 이상일 경우 대문자로 출력(A, B, C, ...)
string itos(int input, int out_base) {
string output;
while(input > 0) {
char ch = input % out_base;
output.insert(0, 1, ch + ((ch <= 9) ? '0' : 'A' - 10));
input /= out_base;
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment