转换数据类型 [英] Converting Datatypes
问题描述
您好,
我在c:
WORD calcChecksum(BYTE数据[],WORD长度)
{
WORD * i_data;
WORD校验和= 0;
字节i = 0;
i_data =(WORD *)数据;
数据..这是数据[0]在128处,并由上面的
语句改为6272。
in c#我这样做了
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data =(ushort)data [0];
但是i_data dos在这里不会改变。
帮助!
并且谢谢
C#没有指针。你将data [0]的值放入i_data。
你必须重新考虑你正在做的事情。
AMP写道:
你好,
我有c:
WORD calcChecksum(BYTE数据[],WORD长度)
{
WORD * i_data;
WORD校验和= 0;
字节i = 0;
i_data =(WORD *)数据;
数据..这是数据[0]来自128并由<变为6272 br />
以上陈述。
in c#我这样做了
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data =(ushort)data [0];
但是i_data不会在这里改变。
帮助!
并且谢谢
< blockquote>应该没关系i_data =(WORD *)数据正在转换
数据中的值(这是128的字节值)到了一个价值为
6272的WORD(ushort)...每次。
我不知道怎么做,但我不认为指针是相对的。
Ian Semmel写道:
C#没有指针。你将data [0]的值放入i_data。
你必须重新考虑你正在做的事情。
AMP写道:
你好,
我有c:
WORD calcChecksum(BYTE数据[],WORD长度)
{
WORD * i_data;
WORD校验和= 0;
字节i = 0;
i_data =(WORD *)数据;
数据..这是数据[0]来自128并由<变为6272 br />
以上陈述。
in c#我这样做了
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data =(ushort)data [0];
但是i_data不会在这里改变。
帮助!
并且谢谢
实际上,C#*确实*有指针。它们处于不安全的环境中,但是它们是
是托管指针。
-
HTH,
< br $>
Kevin Spencer
微软MVP
鸡肉沙拉手术
你所寻求的是你得到的。
" Ian Semmel" <是*********** @ NOKUNKrocketcomp.com.auwrote in message
news:eg ************** @ TK2MSFTNGP02。 phx.gbl ...
C#没有指针。你将data [0]的值放入
i_data。
你将不得不重新考虑你正在做的事情。
>
AMP写道:
>您好,
我在c:
WORD calcChecksum(BYTE data [],WORD长度)
{WORD * i_data;
WORD校验和= 0;
BYTE i = 0;
i_data =(WORD *)数据; <数据..这是数据[0]来自128并通过上面的
语句改为6272.
在c#中我做了这个
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data =(ushort)data [0];
帮助!
并且谢谢
Hello,
I have in c:
WORD calcChecksum(BYTE data[], WORD length)
{
WORD* i_data;
WORD checksum= 0;
BYTE i= 0;
i_data= (WORD*)data;
data.. which is data[0] comes in at 128 and gets changed to 6272 by the
statement above.
in c# i did this
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data = (ushort)data[0];
but i_data dos not change here.
Help!
And Thanks
C# does not have pointers. You are putting the value of data[0] into i_data.
You will have to rethink whatever you are doing.
AMP wrote:Hello,
I have in c:
WORD calcChecksum(BYTE data[], WORD length)
{
WORD* i_data;
WORD checksum= 0;
BYTE i= 0;
i_data= (WORD*)data;
data.. which is data[0] comes in at 128 and gets changed to 6272 by the
statement above.
in c# i did this
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data = (ushort)data[0];
but i_data dos not change here.
Help!
And Thanks
It should not matter i_data=(WORD*)data is converting the value in
data(which is a byte value of 128 to a WORD(ushort) with a value of
6272...every time.
I dont know how, but i dont think the pointer is relative.
Ian Semmel wrote:C# does not have pointers. You are putting the value of data[0] into i_data.
You will have to rethink whatever you are doing.
AMP wrote:Hello,
I have in c:
WORD calcChecksum(BYTE data[], WORD length)
{
WORD* i_data;
WORD checksum= 0;
BYTE i= 0;
i_data= (WORD*)data;
data.. which is data[0] comes in at 128 and gets changed to 6272 by the
statement above.
in c# i did this
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data = (ushort)data[0];
but i_data dos not change here.
Help!
And Thanks
Actually, C# *does* have pointers. They are in an unsafe context, but they
are managed pointers.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
What You Seek Is What You Get.
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.auwrote in message
news:eg**************@TK2MSFTNGP02.phx.gbl...C# does not have pointers. You are putting the value of data[0] into
i_data.
You will have to rethink whatever you are doing.
AMP wrote:>Hello,
I have in c:
WORD calcChecksum(BYTE data[], WORD length)
{
WORD* i_data;
WORD checksum= 0;
BYTE i= 0;
i_data= (WORD*)data;
data.. which is data[0] comes in at 128 and gets changed to 6272 by the
statement above.
in c# i did this
ushort i_data;
ushort checksum = 0;
byte i = 0;
i_data = (ushort)data[0];
but i_data dos not change here.
Help!
And Thanks
这篇关于转换数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!