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. 6 2925
On Fri, 30 Jul 2004 10:11:00 +0800, "Magix" <ma***@asia.com> wrote in
comp.lang.c: 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.
There's nothing particularly wrong with what you posted. Copy the
real code from your editor and paste the actual text into another
post.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Magix wrote on 30/07/04 : int MSB; int LSB; int Total; char buf[5];
MSB = (0x07 << 8) LSB= (0xD4 & 0x00FF) Total = MSB | LSB sprintf(buf, "%d",Total);
This code is not compiling. Please post the exact code that is not
working.
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
I should work this way but try %i instead of %d.
--
cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
"Magix" <ma***@asia.com> schrieb im Newsbeitrag
news:41********@news.tm.net.my... 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.
cody wrote on 30/07/04 : I should work this way but try %i instead of %d.
Why ? What do you think the difference is with printf()?
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"
"Magix" <ma***@asia.com> wrote in message news:41********@news.tm.net.my... 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 ?
It doesn't compile. Besides, you omitted the most important piece of the
puzzle: the offending printf statement. Try this:
#include <stdio.h>
int main(void)
{
int MSB;
int LSB;
int Total;
char buf[5];
MSB = (0x07 << 8);
LSB= (0xD4 & 0x00FF);
Total = MSB | LSB;
sprintf(buf, "%d",Total);
printf("%s\n", buf);
return 0;
}
--
Tim Hagan
Magix wrote: 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.
You're missing at least three semicolons.
#include <stdio.h>
int main(void)
{
int MSB;
int LSB;
int Total;
char buf[5];
MSB = (0x07 << 8);
LSB = (0xD4 & 0x00FF);
Total = MSB | LSB;
sprintf(buf, "%d", Total);
printf("%s\n", buf);
return 0;
}
Mine works, why not yours? :-)
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randell D. |
last post by:
Why would one use bitwise operators? I can program in various languages in
some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise
operators before, but never understood why...
|
by: Joe Gonzalez |
last post by:
Is it possible to perform bitwise operations in selects in DB2 8.1? In
postgres I can say something like SELECT ... FROM <sometable> WHERE
RecFlags && 0x08 <> 0 to get a bitwise and operation. I...
|
by: Jerry |
last post by:
I want an algorithm that do arithmetic operations(divide,mutiply,add
etc.)just using bitwise operators:<<,>>,&,|,^;
For example,how "a/10" can be implemented.
I just want a hint.
Thanks.
|
by: Steve Summit |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
It's often explained that the reason for some of the imprecision
in C's definition is so that C can be implemented on different
kinds of machines -- say, those...
|
by: Paul E Collins |
last post by:
Suppose I have a few Keys objects:
Keys k1 = Keys.V; // V
Keys k2 = Keys.Control | Keys.V; // Ctrl+V
Keys k3 = Keys.Shift | Keys.J; // Shift+J
I need to determine which of these include the...
|
by: Emilio |
last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
|
by: David R. |
last post by:
I want to do bitwise operation on some large integers.
For example,
Response.Write CBool(2 AND 2^30) ' returns False
Response.Write CBool(2 AND 2^31) ' CRASHED!
Looks like the AND...
|
by: Marc |
last post by:
I'm trying to set the first three bits to zero on a byte. For some reason,
the compiler is casting the number peculiarly when I use the bitwise
complement operator.
Here's what I think should...
|
by: Carramba |
last post by:
Hi!
I now that I can't do straight forward any bitwise operation on float
(double etc..). But I wondering what is the easiest/best way to do this?
I was thinking if I have float x=1.1111 so I can...
|
by: Sakhtkoosh |
last post by:
I have written a program in C environment. I need to do operation on codes with more than 64 elements whose values are 0 and 1. At first, I simulated it with an array in 2 dimension(n*m) but after...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |