开发者

Character assignment issue with Objective C

I am try to assign the value to char like this

char Cipher1[16] = {55,149,31,253,212,158,217,64,226,62,149,241,255,147,115,155};

but after assigning it assign the this value t开发者_运维问答o Chiper1 not exact value 

  55 -107 31 -3 -44 -98 -39 64 -30 62 -107 -15 -1 -109 115 -101 

is this correct assignment to char in objective c


this is just a difference between signed and unsigned byte ... print it in the form of unsigned char and you should get the same result.

Note: char --- is signed so value greater then 128 take 8 bits to hold -- all values greater then 128 are shown in negative(it refers to the sign bit.)


Isn't char signed, so hence in the range -128 to +127, so your values are being cast to signed values?

Surely you want unsigned char if you want values in the range 0 to 255?

Also agree with Vladimir, how are your ouputting the values, are you sure it's not the output that's the issue?


You are right now using signed char. Instead, switch to unsigned:

unsigned char Cipher1[16] = {55,149,31,253,212,158,217,64,226,62,149,241,255,147,115,155}; 

This will give you the correct result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜