# I have a question about the pointer! *z = ~(hap & 0xFF); What does ~ mean in?

Asked 1 weeks ago, Updated 1 weeks ago, 7 views

Hello! I am leaving a question because I have a question while studying C language! First of all, it was understood that the while statement was executed to output the cnt value and the hap value After that, I couldn't understand the if statement, so I left a question.

`*z = ~(hap & 0xFF);I understand that hap & 0xFF is 11 in the ` part I can't find what `~` means. Also, I'm not sure why `*z` becomes `244`.

``````#include <stdio.h>
unsigned char test(unsigned char*, int, int);

int main(void)
{
unsigned char message = { 'A', 'B', 'C', 'D' };
unsigned char ans;
test(&message, 5, 1);
printf("Result on transmission = %d\n", (int)message);
ans = test(&message, 5, 2);
printf("Results upon receipt = %d\n", (int)ans);
return 0;
}

unsigned char test(unsigned char* p, int cnt, int flag)
{
unsigned short int hap = 0;
unsigned char* z;
z = p;
while (cnt--)
{
hap = hap + *p--;
if (hap & 0xFF00)
{
hap = hap & 0xFF;
hap = hap + 1;
}
printf("cnt = %d hap = %d\n", cnt, hap);
}
if (flag == 1)
{
*z = ~(hap & 0xFF);
return 0;
}
else
return ~(hap & 0xFF);
}
``````

c

2022-09-19 23:20

`~` is a bit inversion operator. Since z is char type, if you think of just 8 bits, the binary value of 11 in `~11` is 00001011 and the bit inversion is 11110100. This value is 244 in decimal.

2022-09-19 23:20

Popular Tags
python x 1174
android x 247
c x 235
java x 192
javascript x 106
mysql x 30
html x 27
node.js x 24
php x 21
list x 19