Bitwise operation

From: Magix (magix_at_asia.com)
Date: 07/30/04


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.



Relevant Pages

  • Re: Bitwise operation
    ... > int MSB; ... > int LSB; ... > When I print buf in %s format, the output I expected is 2004. ...
    (comp.lang.c)
  • [PATCH 1/3] [MTD] Flex-OneNAND support
    ... endif # MTD_ONENAND ... int value, block, page; ... * MLC NAND Flash cell has paired pages - LSB page and MSB page. ... int ret; ...
    (Linux-Kernel)
  • Re: strange use of format specifier in printf
    ... int TestByteOrder() ... This fails to identify middle-endian systems. ... Then set its third LSB to 2. ... and don't have my code directory with me... ...
    (comp.lang.c)
  • Re: How does C handle issues arising out of Endianness?
    ... the LSB of the unknown ... Are shift operators better examples of the question I have? ... As in the following snippet (please do let me know if I need to follow ... int x = 10; ...
    (comp.lang.c)
  • Re: creating int from contiguous bits in an int
    ... unsigned long long extractValue(unsigned long long target, int a, int ... The idea is that we shift enough bits to the left for the desired MSB to be the actual MSB, then shift back to make the desired LSB the actual LSB, losing undesired bits in the overflow. ... unsigned long long extractValue(unsigned long long target, int msb, int lsb) { ...
    (comp.lang.c)