回复:常见问题解答20-12 [英] Re: FAQ 20-12

查看:58
本文介绍了回复:常见问题解答20-12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

7月3日,6:51 * pm,viza< tom.v ... @ gm-il.com.obviouschange.invalid>

写道:

On Jul 3, 6:51*pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
wrote:


* * do {

* * * * * ** - p =" 0123456789abcdef" [num%base]; * LT;< -------这个
* *do {
* * * * * **--p = "0123456789abcdef"[num % base]; *<< -------This


line让我感到困惑?如果有人可以提供帮助,我会很感激。
line has me confused? If someone could help, I will appreciate it.



让我把它分开:


do {

* char hexidecimal_digits [ ] = {''0'',''1'',''2'',......等};


* p = p - 1;


* * p = hexidecimal_digits [num%base];


你可能不理解的唯一一点数学是(num%

base)表示num除以base时的余数。


Let me space it out a bit:

do {
* char hexidecimal_digits[]= {''0'',''1'',''2'', ...etc };

* p= p - 1;

* *p= hexidecimal_digits[ num % base ];

The only bit of maths that you might not understand is that ( num %
base ) means the remainder when num is divided by base.



我从未见过(这不一定意味着什么)一个

字符数组初始化。我很好奇你怎么从这个(0123456789abcdef[num%base];)到这个(char

hexidecimal_digits [] = {''0 '',''1',''2'',......等等;)。 (数学很好

(模数运算符)。谢谢你的帮助。


I have just never seen ( not that that necessarily means anything) a
char array initialized like that. I am curious as to how you get from
this ("0123456789abcdef"[num % base];) to this (char
hexidecimal_digits[]= {''0'',''1'',''2'', ...etc };). ( The math is fine
( viz the modulo operator). Thank you for your help.

推荐答案

mdh说:
mdh said:

7月3日下午6:51,viza< tom.v ... @ gm-il.com.obviouschange.invalid>

写道:
On Jul 3, 6:51 pm, viza <tom.v...@gm-il.com.obviouschange.invalid>
wrote:

do {

* - p =" 0123456789abcdef" [num%base];<< -------这个
do {
*--p = "0123456789abcdef"[num % base]; << -------This


>行让我感到困惑?如果有人可以帮助,我将不胜感激。
>line has me confused? If someone could help, I will appreciate it.


让我稍微说清楚:

做{\\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ r \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ necc '',''1',''2',......等};

p = p - 1;

* p = hexidecimal_digits [num%你可能不理解的唯一一些数学是(num%
base)表示num除以base时的余数。


Let me space it out a bit:

do {
char hexidecimal_digits[]= {''0'',''1'',''2'', ...etc };

p= p - 1;

*p= hexidecimal_digits[ num % base ];

The only bit of maths that you might not understand is that ( num %
base ) means the remainder when num is divided by base.




我从来没有见过(这不一定意味着什么)一个初始化的

char数组。我很好奇你怎么从这个(0123456789abcdef[num%base];)到这个(char

hexidecimal_digits [] = {''0 '',''1',''2'',......等等;)。



I have just never seen ( not that that necessarily means anything) a
char array initialized like that. I am curious as to how you get from
this ("0123456789abcdef"[num % base];) to this (char
hexidecimal_digits[]= {''0'',''1'',''2'', ...etc };).



来吧迈克尔,他只是将它分散一点,以帮助你看到

逻辑,这就是全部。没有hexadecimal_digits数组,因为它不是必需的
- 字符串文字也可以。但是什么viza

告诉你的是我们可以编写具有相同效果的代码,使用

临时数组而不是字符串文字,你似乎同意

这个等价物很容易理解。


诀窍在于没有技巧。 A[0]是A。 AB[0]也是A,

和AB[1]是B。 ABC[0]是A,ABC[1]是B,ABC[2]是C。


" 0123456789abcdef" [0]为''0''。

" 0123456789abcdef" [1]为''1'。

" 0123456789abcdef" [9] is''9''。

" 0123456789abcdef" [10] is''a''。

" 0123456789abcdef" [11] is ''b''。


现在清除?


-

Richard Heathfield< http:/ /www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Come on Michael, he''s just spreading it out a little to help you see the
logic, that''s all. There is no hexadecimal_digits array, because it isn''t
necessary - the string literal will do just as well. But what viza is
telling you is that we could write code that has the same effect, using a
temporary array instead of a string literal, and you seem to agree that
this equivalent would be easy to understand.

The trick is that there is no trick. "A"[0] is ''A''. "AB"[0] is also ''A'',
and "AB"[1] is ''B''. "ABC"[0] is ''A'', "ABC"[1] is ''B'', "ABC"[2] is ''C''.

"0123456789abcdef"[0] is ''0''.
"0123456789abcdef"[1] is ''1''.
"0123456789abcdef"[9] is ''9''.
"0123456789abcdef"[10] is ''a''.
"0123456789abcdef"[11] is ''b''.

Clear now?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


mdh写道:
mdh wrote:

>
>



.... snip ...

.... snip ...


>

我从来没有见过(这不一定意味着什么)

a char数组初始化。我很好奇你怎么从这个(0123456789abcdef[num%base];)到这个(char

hexidecimal_digits [] = {''0 '',''1',''2'',......等等;)。 (数学很好

(模数运算符)。谢谢你的帮助。
>
I have just never seen ( not that that necessarily means anything)
a char array initialized like that. I am curious as to how you get
from this ("0123456789abcdef"[num % base];) to this (char
hexidecimal_digits[]= {''0'',''1'',''2'', ...etc };). ( The math is fine
(viz the modulo operator). Thank you for your help.



为什么难度?012。 ..def"是一个char数组.num%base是一个在0到15范围内的
数字,只要num和base是

为正数,而base是范围1到16.因此

" 0123 ... def" [num%base]选择其中一个字符。


-

[mail]:Chuck F(cinefalconer at maineline dot net)

[page]:< http://cbfalconer.home.att.net>

尝试下载部分。

Why the difficulty? "012...def" is a char array. num % base is a
number in the range 0 through 15 as long as num and base are
positive, and base is in the range 1 through 16. Therefore
"0123...def"[num % base] selects one of those characters.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


7月3日,10:34 * pm,Richard Heathfield< r ... @ see.sig。 invalidwrote:
On Jul 3, 10:34*pm, Richard Heathfield <r...@see.sig.invalidwrote:

mdh说:
mdh said:


来吧Michael,他只是把它分散一点,以帮助你看到

逻辑,这就是全部。
Come on Michael, he''s just spreading it out a little to help you see the
logic, that''s all.



对我来说听起来很合乎逻辑! />

没有hexadecimal_digits数组,因为它不是


Sounds perfectly logical to me!

There is no hexadecimal_digits array, because it isn''t


必需 - 字符串文字也可以。
necessary - the string literal will do just as well.



.... snip ....

....snip....


诀窍在于没有技巧。 A[0]是A。 AB[0]也是A,

和AB[1]是B。 ABC[0]是A,ABC[1]是B,ABC[2]是C。


" 0123456789abcdef" [0]为''0''。

" 0123456789abcdef" [1]为''1'。

" 0123456789abcdef" [9] is''9''。

" 0123456789abcdef" [10] is''a''。

" 0123456789abcdef" [11] is ''b''。


现在清除?
The trick is that there is no trick. "A"[0] is ''A''. "AB"[0] is also ''A'',
and "AB"[1] is ''B''. "ABC"[0] is ''A'', "ABC"[1] is ''B'', "ABC"[2] is ''C''.

"0123456789abcdef"[0] is ''0''.
"0123456789abcdef"[1] is ''1''.
"0123456789abcdef"[9] is ''9''.
"0123456789abcdef"[10] is ''a''.
"0123456789abcdef"[11] is ''b''.

Clear now?



是的......我已经回去看了K& R并同意这是一个非常巧妙的方式。我想说的是,即使

构造我是一个字符串文字在K& R中得到了很好的解释,我没有意识到人们可以通过使用

紧跟其后的运算符[]来引用常量中的每个字符。我所知道的是,当我在过去只是假装的时候,它经常让我进入

热水...所以我知道我可以在这里询问我所有的假设都将是

迅速纠正!!! :-)

谢谢理查德。

Yep...I have gone back and looked at K&R and agree it is a very neat
way of doing this. What I was trying to say was that even though the
construct "I am a string literal" is well explained in K&R, I was not
aware that one could refer to each character in the constant by using
the operator [] immediately following it. All I know is that when I
have simply assumed things in the past, it has often gotten me into
hot water...so I know I can ask here and all my assumptions will be
rapidly corrected!!! :-)
Thank you Richard.


这篇关于回复:常见问题解答20-12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆