say have the following union :
typedef union { char array[8]; uint64_t u64; } my_type ; i want shift 1 bit 1 through 64 bits reserved, here i've tried :
........................... my_type vector ={0}; short index =0; ( index=0 ; index <64;index++){ printf(" u64 : %d\n", vektor.u64); vektor.u64 = (1<<index) ; } the output fine tell 15th, , it's not problem printf parameters, value definitly wrong = 0 . here output :
u64 : 0 u64 : 1 u64 : 2 u64 : 4 u64 : 8 u64 : 16 u64 : 32 u64 : 64 u64 : 128 u64 : 256 u64 : 512 u64 : 1024 u64 : 2048 u64 : 4096 u64 : 8192 u64 : 16384 u64 : -32768 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 u64 : 0 so question is, i'm doing wrong ? way i'm using atmelstudio6.2.
another problem besides formatting pointed out sourav, value 1 int, , it's unlikely int 64 bits (in fact, seems me on platform int 16 bits).
you need use e.g. 1ull unsigned long long can shifted 64 bits.
Comments
Post a Comment