Bitwise operation
From: Magix (magix_at_asia.com)
Date: 07/30/04
- Next message: John: "free'ing malloc'd structure with malloc'd members"
- Previous message: Mr. X: "Really odd pointer behavior"
- Next in thread: Jack Klein: "Re: Bitwise operation"
- Reply: Jack Klein: "Re: Bitwise operation"
- Reply: Emmanuel Delahaye: "Re: Bitwise operation"
- Reply: cody: "Re: Bitwise operation"
- Reply: Tim Hagan: "Re: Bitwise operation"
- Reply: Joe Wright: "Re: Bitwise operation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Jul 2004 10:11:00 +0800
Hi,
I want to manipulate an incoming WORD as I receive byte by byte. let say 07
D4, which is 2004
I want to combine these two bytes and convert into decimal, then convert as
a string. (sprintf)
int MSB;
int LSB;
int Total;
char buf[5];
MSB = (0x07 << 8)
LSB= (0xD4 & 0x00FF)
Total = MSB | LSB
sprintf(buf, "%d",Total);
When I print buf in %s format, the output I expected is 2004. But it prints
"-long printf)d"
What is wrong in my code above ?
Thanks.
- Next message: John: "free'ing malloc'd structure with malloc'd members"
- Previous message: Mr. X: "Really odd pointer behavior"
- Next in thread: Jack Klein: "Re: Bitwise operation"
- Reply: Jack Klein: "Re: Bitwise operation"
- Reply: Emmanuel Delahaye: "Re: Bitwise operation"
- Reply: cody: "Re: Bitwise operation"
- Reply: Tim Hagan: "Re: Bitwise operation"
- Reply: Joe Wright: "Re: Bitwise operation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|