Ok so I make my masks

short m1, m2, m3, m4;

m1 = 0xF000;
m2 = 0x0F00;
m2 = 0x00F0;
m3 = 0x000F;

and then I test my masks

printf("%hd %hd %hd %hd\n", m1, m2, m3, m4);

when I test it the values come out as

-4096 240 15 0

which is equal to

0xF000
0x00F0
0x000F
0x0000

which is messing up my checksum program when I try to apply the masks. :-\

Any advice?

Ok so I make my masks

short m1, m2, m3, m4;

m1 = 0xF000;
m2 = 0x0F00;
m2 = 0x00F0;
m3 = 0x000F;

and then I test my masks

printf("%hd %hd %hd %hd\n", m1, m2, m3, m4);

when I test it the values come out as

-4096 240 15 0

which is equal to

0xF000
0x00F0
0x000F
0x0000

which is messing up my checksum program when I try to apply the masks. :-\

Any advice?

I tried initializing the values like this and it worked

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{

short m1 = 0xf000, m2 = 0x0f00, m3 = 0x00f0, m4 = 0x000f;

printf("%hd %hd %hd %hd\n", m1, m2, m3, m4);

exit(EXIT_SUCCESS);
}

What are you using for a compiler?

gcc on a unix machine

Used unsigned integral types when dealing with bits.

#include <stdio.h>
#include <stdlib.h>

int main()
{
   unsigned short m1 = 0xf000, m2 = 0x0f00, m3 = 0x00f0, m4 = 0x000f;
   printf("%hu %hu %hu %hu\n", m1, m2, m3, m4);
   printf("%hx %hx %hx %hx\n", m1, m2, m3, m4);
   return 0;
}

/* my output
61440 3840 240 15
f000 f00 f0 f
*/

[edit]Part of the reason for your "strange" output:

Ok so I make my masks

short m1, m2, m3, m4;

m1 = 0xF000;
m2 = 0x0F00;
m2 = 0x00F0;
m3 = 0x000F;

You don't give m4 a value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.