तो मैं सी के लिए नौसिखिया का थोड़ा सा हूं और मुझे यह जानकर उत्सुकता है कि मुझे यह असामान्य व्यवहार क्यों मिल रहा है।सी मेरे हेक्स मानों को गलत तरीके से प्रिंट क्यों करता है?
मैं एक समय में एक फ़ाइल 16 बिट पढ़ रहा हूँ और सिर्फ उन्हें बाहर मुद्रण इस प्रकार है।
#include <stdio.h>
#define endian(hex) (((hex & 0x00ff) << 8) + ((hex & 0xff00) >> 8))
int main(int argc, char *argv[])
{
const int SIZE = 2;
const int NMEMB = 1;
FILE *ifp; //input file pointe
FILE *ofp; // output file pointer
int i;
short hex;
for (i = 2; i < argc; i++)
{
// Reads the header and stores the bits
ifp = fopen(argv[i], "r");
if (!ifp) return 1;
while (fread(&hex, SIZE, NMEMB, ifp))
{
printf("\n%x", hex);
printf("\n%x", endian(hex)); // this prints what I expect
printf("\n%x", hex);
hex = endian(hex);
printf("\n%x", hex);
}
}
}
परिणाम कुछ इस तरह दिखाई:
ffffdeca
cade // expected
ffffdeca
ffffcade
0
0 // expected
0
0
600
6 // expected
600
6
क्यों पिछले प्रत्येक ब्लॉक में लाइन दूसरा रूप में एक ही मूल्य प्रिंट नहीं करता किसी को भी मुझे समझा सकते हैं?