如何将__int64传递给unsigned char [16] [英] how pass an __int64 to unsigned char [16]
问题描述
我有一个结构allmsg和他的成员:
Hi,
I have a struct "allmsg" and him member :
推荐答案
好的,
所以要恢复我之前写的所有内容。
我有这个结构:
Ok,
So for resuming all I wrote before.
I have this struct :
struct frame_message {
// typedef struct {
unsigned int sender_id;
unsigned int encrypt_key_id;
unsigned int encrypt_size;
unsigned int crc ;
unsigned int data_length;
unsigned int sequence_number;
unsigned int packet_type;
unsigned int read_number;
unsigned char card_number [16] ; /////
unsigned int pin_code;
unsigned char padding_bytes [MAX_PADDING];
} allmsg;
struct frame_message {
//typedef struct {
unsigned int sender_id;
unsigned int encrypt_key_id;
unsigned int encrypt_size;
unsigned int crc;
unsigned int data_length;
unsigned int sequence_number;
unsigned int packet_type;
unsigned int read_number;
unsigned char card_number[16];/////
unsigned int pin_code;
unsigned char padding_bytes[MAX_PADDING];
}allmsg;
我传给allmsg.card_number一个_int64,但这不是好办法
And I pass to allmsg.card_number an _int64 but it is not good way
fonction pass(_int64 badgeid)
{
allmsg.card_number =(unsigned char *)& badgeid; // erreur不兼容的signes assignement of(unsigned char * to unsigned char [16]
...
}
fonction pass(_int64 badgeid)
{
allmsg.card_number=(unsigned char*)&badgeid; //erreur incompatible signes assignement of (unsigned char* to unsigned char [16]
...
}
你能解决我吗?
谢谢
Could you fix me please ?
Thank you
__ int64是8个字节很长,所以我不明白为什么你要用8字节数填充一个16字节的数组?除非你想做这样的事情:
__int64 is 8 bytes long,so I don''t see why are you trying to fill a 16byte array with 8 byte number?Unless you want to do something like this:
谢谢Savage,
确切地说,我想要:_int64中的包含必须是s card_number [16]中的ame(但以字节为单位)格式。
例如,当我显示变量的符号时:
Thank you Savage,
Exactly, I want : the contain in _int64 must be the same (but in bytes) format in card_number[16] .
For example when I display containt of my variables:
//(tempfadge_id的printf)
数据:CARD NUMBER = 123456789
//(printf for allmsg.card_number [])
0 [0x00],1 [0x00],2 [0x00],3 [0x00],4 [0xB7],5 [0xFA],6 [0x09],7 [0xC8],8 [ 0x00],9 [0x00],10 [0x00],11 [0x00],12 [0x07],13 [0x5B],14 [0xCD],
15 [0x15],
//(printf of temp_badge_id )
data: CARD NUMBER = 123456789
//(printf for of allmsg.card_number[] )
0[0x00], 1[0x00], 2[0x00], 3[0x00], 4[0xB7], 5[0xFA], 6[0x09], 7[0xC8], 8[0x00], 9[0x00], 10[0x00], 11[0x00], 12[0x07], 13[0x5B], 14[0xCD],
15[0x15],
就像你看到long long int:十六进制的123456789是75BCD15(字节12 - > 15)
但含有byes 4 - > 7 ??奇怪
我认为问题来自此处:
Like you see long long int: 123456789 in hex is 75BCD15 (bytes 12 -> 15 )
but what is contain of byes 4 -> 7 ?? strange
I think that problems come before from here:
allmsg.card_number [15] = ptemp_badge_id [15];
allmsg.card_number [14] = ptemp_badge_id [14];
...
..
allmsg.card_number [0] = ptemp_badge_id [0];
allmsg.card_number[15]=ptemp_badge_id[15];
allmsg.card_number[14]=ptemp_badge_id[14];
...
..
allmsg.card_number[0]=ptemp_badge_id[0];
但是我不确定?
所以也许iproblem正确地将__int64传递给16字节的unsigned char []
谢谢
But I''m not sure ?
So maybe iproblem is to pass correctly __int64 to unsigned char [] of 16 bytes
Thank you
这篇关于如何将__int64传递给unsigned char [16]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!