字符字节str [i]被视为已签名,我需要无符号 [英] character byte str[i] treated as signed, I need unsigned

查看:128
本文介绍了字符字节str [i]被视为已签名,我需要无符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在比较角色通过


return(str1 [i] - str2 [i]);


和我'将8位字符视为已签名

而非无符号整数存在问题。反汇编使用


movsx eax,byte ptr [edx]


将我的角色加载到EAX寄存器中。我需要它来使用movzx。

如何重新编码以将我的字符视为无符号而不是签名?

I''m comparing characters via

return(str1[i] - str2[i]);

and I''m having problems with 8-bit characters being treated as signed
instead of unsigned integers. The disassembly is using

movsx eax,byte ptr[edx]

to load my character in to EAX register. I need it to use movzx.
How can I recode this to treat my characters as unsigned instead of signed?

推荐答案

Susan Rice写道:
Susan Rice wrote:

我正在通过
比较字符

return(str1 [i] - str2 [i ]);


我遇到8位字符被视为签名的问题

而不是无符号整数。反汇编使用


movsx eax,byte ptr [edx]


将我的角色加载到EAX寄存器中。我需要它来使用movzx。

如何重新编码这个以将我的字符视为无符号而不是签名?
I''m comparing characters via

return(str1[i] - str2[i]);

and I''m having problems with 8-bit characters being treated as signed
instead of unsigned integers. The disassembly is using

movsx eax,byte ptr[edx]

to load my character in to EAX register. I need it to use movzx.
How can I recode this to treat my characters as unsigned instead of signed?



通过定义(或者如果所有其他方法都失败)将它们转换为无符号。你

没有显示str1或str2的定义。


-

Ian Collins。

By defining (or if all else fails) casting them as unsigned. You
haven''t shown the definition of str1 or str2.

--
Ian Collins.


在文章< FZ ***************** @ newsfe10.phx>,

Susan Rice< ; sr **** @ cox.netwrote:
In article <FZ*****************@newsfe10.phx>,
Susan Rice <sr****@cox.netwrote:

>我正在通过
比较字符
>I''m comparing characters via


return(str1 [i] - str2 [i]);
return(str1[i] - str2[i]);


>我遇到的问题是将8位字符视为已签名
而非无符号整数。反汇编使用
>and I''m having problems with 8-bit characters being treated as signed
instead of unsigned integers. The disassembly is using


movsx eax,byte ptr [edx]
movsx eax,byte ptr[edx]


>将我的角色加载到EAX寄存器中。我需要它来使用movzx。
如何重新编码这个以将我的字符视为无符号而不是签名?
>to load my character in to EAX register. I need it to use movzx.
How can I recode this to treat my characters as unsigned instead of signed?



汇编级别的任何内容超出了此新闻组的范围,

不涉及实现细节。


幸运的是,你不需要达到那个水平。试试吧


return((unsigned char)str1 [i] - (unsigned char)str2 [i]);


-

没有人有权通过要求经验证据来摧毁另一个人的信念。 - Ann Landers

Anything down at the assembly level is out of scope for this newsgroup,
which does not deal with implementation specifics.

Fortunately, you do not need to go down to that level. Try just

return( (unsigned char)str1[i] - (unsigned char)str2[i] );

--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers


Susan Rice写道:
Susan Rice wrote:

我正在通过
比较角色

return(str1 [i] - str2 [i]);
I''m comparing characters via

return(str1[i] - str2[i]);



如何声明str1,str2和i?功能的其余部分是什么?

如何使用结果?

How are str1, str2 and i declared? What''s the rest of the function?
How is the result meant to be used?


我遇到了问题8位字符
and I''m having problems with 8-bit characters



为什么你关心角色中有多少位?

Why do you care how many bits in a character there are?


被视为有符号而不是无符号整数。
being treated as signed instead of unsigned integers.



你告诉我们你问题是什么,而不是解释问题本身的b
我输入了这个,输出

我得到了这个,我想要的输出就是这个,这是我的代码

以及它的意图。


[换句话说,不要告诉我们标志差异是你的问题,

告诉我们

_why_ it 这是一个问题。


你应该知道,这个膝盖反射会解决这个问题。回复可能不是解决代码中其他重要问题的问题。例如,您的

方法不保证按字母顺序排列。


[换句话说,您的极简主义演示可能意味着您只能获得

a表面问题(也可能是破损的)解决你的问题,而

更深层次的代码问题未经修正。]

You''re telling us what you _think_ the problem is, rather than
explaining the problem itself, e.g. "i inputted this, the output
I got was this, the output I wanted was this, here is my code
and what it is meant to do."

[In other words, don''t tell us the sign difference is your problem,
tell us
_why_ it''s a problem.]

You should know that knee-jerk "this''ll fix it" responses may not be
addressing other important issues of your code. For instance, your
methodology is not guaranteed to yeild alphabetical ordering.

[In other words, your minimalist presentation may mean you only get
a superficial (and possibly broken) solution to your problem, whilst
deeper issues with your code are left uncorrected.]


反汇编正在使用


movsx eax,byte ptr [edx]
The disassembly is using

movsx eax,byte ptr[edx]



通过检查反汇编来学习C是最糟糕的事情你可以

做。当你改变架构的时候,你可能会发现你需要忘记的那些可能很多的b $ b b b b。


- -

彼得

Learning C by examining the disassembly is the WORST thing you can
do. When you change architectures you may find that there''s an awful
lot of assumtions on your part that you''ll have to unlearn.

--
Peter


这篇关于字符字节str [i]被视为已签名,我需要无符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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