整数转16进制字符串,不用系统函数
来源:互联网 发布:linux中cat命令详解 编辑:程序博客网 时间:2024/04/28 17:22
伪代码:
ConvertInt2Hex: dim n,hexStr loop: if n == 0 break; dim tmp = n % 16 if tmp >= 0 && tmp <= 9 hexStr <- hexStr.append('0' + tmp) else hexStr <- hexStr.append('a'+tmp-10) n <- n / 16 end loop reverse(hexStr) end ConvertInt2Hex
c++
#include <stdio.h>#include <string.h>int main(){int input=0;int temp=0;int i=0;int j=0;char result[100];printf("input a number:\n");scanf("%d",&input);while(input!=0){temp=input%16;if(temp>=0 && temp<10){result[i]=temp+'0';i++;}else{result[i]=temp+'A'-10; i++;}input=input/16;}result[i]='\0';for (j=strlen(result)-1;j>=0;j--){printf("%c",result[j]);}printf("\n");return 0;}
# include <iostream># include <sstream>using namespace std;int main(){ const char map[] = "0123456789ABCDEF"; unsigned int i = 0xABCDEF12; stringstream buffer; while (i) { buffer << map[i % 16]; i /= 16; } buffer << ends; string tmp = buffer.str(); string s(tmp.rbegin(), tmp.rend()); cout << s << endl; return 0;}
0 0
- 整数转16进制字符串,不用系统函数
- 编写整数字符串转化函数(不用itoa与atoi)
- 将16进制字符串转换为整数的函数
- 字符串转成16进制整数的函数
- double浮点数转字符串算法,不用sprintf等系统转换函数.
- java 把字符串转化成数字(不用JAVA系统函数)
- 自定义函数实现字符串转成整数,参照系统函数atoi
- 怎么样将整数转化为字符串数,并且不用函数itoa
- 怎样将整数转化成字符串数,并且不用函数itoa
- C语言实现将整数转化成字符串数,不用函数itoa
- 不用库函数实现整数转换为字符串
- 输入两个字符串,不用系统提供的函数strcat,自定义函数将两个字符串连接起来。
- 16进制字符串转16进制整数
- 字符串和16进制整数转换
- 16进制整数转化成字符串
- 字符串转整数函数stoi()实现
- C语言整数转字符串itoa函数
- C语言字符串转整数atoi函数
- Delphi中如何调用Excel VBA
- Servlet的学习
- JAVA中的常量定义在class中还是interface中比较合理?
- python3爬虫之旅
- HDU-2870-Largest Submatrix(DP)
- 整数转16进制字符串,不用系统函数
- JDK + eclipse mars + CDT + PyDev
- leetcode 18: 4Sum (KSum)
- android常见错误
- 时过境迁,物是人非。
- xshell的快捷键(非常实用)
- 谷歌电子市场第1天
- 思特沃克作业
- javascript学习笔记--(初级)js文件介绍