English 中文(简体)
我如何把mal酸 in转化为单一六dec特性? (C)
原标题:How do I convert a decimal integer into a single hexadecimal character? (C)

我正试图将mal酸 in转化为hexa。 我在网上做了大量搜索,并找到了许多这样做的方法。 然而,我发现的每一种方式都是改观的;例如,我可将100改为“64”。 这是我需要做的事。 我想能够将100个转换成0x64,这是一个完全不同的问题。 出于某种原因,我怀疑答案非常简单,但我看不出。 我用《方案规划语言》撰写,只是要澄清。 任何援助或想法都会受到高度赞赏。

Thanks, Hassan

最佳回答

您可以把“思考”从小数到六分数,因为它是......的(通常储存在记忆中)。 尽可能在positional Systems上的表述完全与编号线相同。 可在不同的基础上通过 :>。

int num = 15;
printf( "%d", num );   /* prints 15 */
printf( "0x%x", num ); /* prints 0xf */
printf( "0%o", num );  /* prints 017 (octal) */

num = 0xf;
printf( "%d", num );   /* prints 15 */
printf( "0x%x", num ); /* prints 0xf */
printf( "0%o", num );  /* prints 017 (octal) */

num = 017;
printf( "%d", num );   /* prints 15 */
printf( "0x%x", num ); /* prints 0xf */
printf( "0%o", num );  /* prints 017 (octal) */
问题回答

C语言的分类并不真正达到 。 当你说:

int a = 100;
int b = 0x64;

......<代码>a和b具有同等价值。 谈论将<条码>a改为六十二条(或<条码>b)为正数,是毫无意义的。

100 in decimal is in hex, no transformation is need. 愤怒的基础只是解释问题。

页: 1

int i = 100;
char c = i; // c now has the value 0x64 (aka decimal 100)

确实,除了确保<条码>i<>->/条码>不超过255条外,还有你必须做的事情。

只有在印刷或以其他方式向人类展示数字时,才真正地进入新基地。 就记忆中的数字而言,100个为0x64, 1100个。 它们具有同样的价值,因此它们都有相同的限额。

它问你如何用西班牙语展示色绿色。 绿色是绿色的,不管你重新使用什么语言。 只有当你设法把它写成一个字子时,你才会考虑你将使用什么语言。 因此,它有数字,决定你重新使用什么基础。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...