#include<stdio.h>
#include<conio.h>
void main()
{
int x=0x01c0ffee;
int y=x>>15+1&0xff;
clrscr();
printf("%x ",y);
getch();
}
the following code prints ff in turbo c++ and instead of
15+1
if we use
7+1
returns the same answer ff.
so, does turbo c++ considers x>> 8 and x>>16 same on hexa,something like that?
To debug your code, I would suggest breaking down the output into the individual operations, but also check that you have enough room in your variables.
The output of
Size:will show you how many bytes you have forint. You need one byte for every two hexademical digit.Here is the output on my 32-bit machine:
If you see
Size: 2, then there's your problem. Try usinglong int. Also, I would recommend usingunsignedif you're performing shift operations since the behavior of right-shift onsignedvariables is implementation-specific (which means Turbo C could act different from gcc)