0
How to assign 0xFFFF to int16_t correctly?
code: #include <stdio.h> #include <stdlib.h> #include "stdint.h" using namespace std; int main() { int16_t x=-1; printf("x=%04X\n",x); return 0; } output: x=FFFFFFFF How to get x=FFFF here?
2 Antworten
+ 6
I encourage you to use C++'s cout facility instead of printf function.
This code is working fine.
#include <iostream>
#include <stdlib.h>
#include "stdint.h"
using namespace std;
int main() {
int16_t x=-1;
cout << "x = " << hex << x << endl;
return 0;
}
output:
x=ffff
std::hex is a stream manipulator which sets the format flag to hexadecimal.
+ 2
int i=0xffff;
cout << i << endl;
Adapt to suit :)