Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why do you always report an error when doing this bitwise AND operation?
Why do you always report an error when doing this bitwise AND operation?
Supplementary answer:

This is compiled and run with Win-TC. If it cannot be compiled, it may need to be modified according to your compiler. If the output result is wrong, you should adjust the value in table [4].

-

I don't know why I used a string, but 16.

0 and' 0' are different.

0 & amp 1= 1

0 ' & amp 1 ' = 0x 30 & amp; 0x 3 1 = 00 1 10000。 00110001= 0000001is not equal to'1'* * * * * *

In addition, the AND operation cannot directly manipulate arrays and strings.

-

# include & ltstdio.h & gt

# include & ltstring.h & gt

Master ()

{

Structure table

{

Unsigned long Dest

Unsigned long mask;

Unsigned long gate;

Unsigned long integer;

};

Structure table tab[4]={

{0xcb4acd00,0xffffffff,0xcb4acd0 1,0xcb4acd0 1},

{0xcb4ace00,0xffffffff,0xcb4ace0 1,0xcb4ace0 1},

{0xcb4acf00,0xffffffff,0xcb4acf0 1,0xcb4acf0 1},

{0xcb4ad000,0xffffffff,0xcb4ace02,0x CB 4 ace 0 1 } };

Unsigned long integer i 1, i2, i3, i4;

Unsigned long IP;

int I;

int m;

char IP _ str[33]= { 0 };

Printf ("Please enter the destination ip address:");

scanf("%s ",IP _ str);

Sscanf(ip_str, "%d.% d.% d", & ampi 1, & ampi2, & ampi3 and AMPI 4);

IP =(I 1 & lt; & lt24)+(I2 & lt; & lt 16)+(i3 & lt; & lt8)+i4;

for(m = 0; m & lt=3; m++)

If (ip& [m]. Mask==tab[m]。 Target)

Printf("IP data should be transferred to ip:%d.%d.%d.%d\n ",

Tab [m] Internet & amp0xff000000 & gt& gt24,

Tab [m] Internet & 0x0000 & gt>16,

Tab [m] Internet & amp0x0000ff00 & gt& gt8,

Tab [m] Internet & amp0x000000ff);

Printf ("Press any key to exit. \ n ");

getch();

}