473,508 Members | 4,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading decimal data....

Hi all..

I'm trying to program an application for an emmbedded sistem where an
external processor introduces data into my RAM. The thing is some if the
data I have to pick up is written in hexadecimal format, but some other is
written on the memory positions in decimal format. How can I retrieve this
information reading it as decimal?

So far I use this:
#define MYHEXAVAR (uint_16t*(0x200))
//Which would allow me to read data from MYHEXAVAR just declaring it in my
function. Let's say the position 0x200 of my memory contains 0x0012 as a
value
void myfunc ()

{

sprintf(NewKey, "%3u", *MYHEXAVAR);
memcpy(Key, NewKey, 4);

}

or something similar, I've just outline the function because the real one is
much more complex and long and it wouldn't be good to make my point.
so this func would read memory position 0x200 and write the decimal
representation of 0x0012 which is "18". Now my problem is that I need it to
write "12"
Any of you guys have an idea to how to solve this problem.? It should be
fairly easy, but I don't know whats the easiest. I was thinking about doing
the whole conversion manually reading bit to bit, but I am sure there's some
other easier way....
Thanks in advance!

Marc
Nov 14 '05 #1
4 2944
Yodai <yo***@spamnot.mail.vu> scribbled the following:
Hi all.. I'm trying to program an application for an emmbedded sistem where an
external processor introduces data into my RAM. The thing is some if the
data I have to pick up is written in hexadecimal format, but some other is
written on the memory positions in decimal format. How can I retrieve this
information reading it as decimal? So far I use this:
#define MYHEXAVAR (uint_16t*(0x200)) //Which would allow me to read data from MYHEXAVAR just declaring it in my
function. Let's say the position 0x200 of my memory contains 0x0012 as a
value void myfunc ()
{
sprintf(NewKey, "%3u", *MYHEXAVAR);
memcpy(Key, NewKey, 4);
} or something similar, I've just outline the function because the real one is
much more complex and long and it wouldn't be good to make my point.
so this func would read memory position 0x200 and write the decimal
representation of 0x0012 which is "18". Now my problem is that I need it to
write "12"
Any of you guys have an idea to how to solve this problem.? It should be
fairly easy, but I don't know whats the easiest. I was thinking about doing
the whole conversion manually reading bit to bit, but I am sure there's some
other easier way....


Do you want the sprintf() call to write "12" (eighteen in
hexadecimal) into NewKey rather than "18" (eighteen in decimal)? If so,
then change "%3u" to "%2x" and you should be settled.

If this is not the real problem, then please explain in detail what is.
Note that embedded systems, external processors, and even physical
memory locations are a feature of the computer system itself, not of C.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"As we all know, the hardware for the PC is great, but the software sucks."
- Petro Tyschtschenko
Nov 14 '05 #2


Yodai wrote:
Hi all..

I'm trying to program an application for an emmbedded sistem where an
external processor introduces data into my RAM. The thing is some if the
data I have to pick up is written in hexadecimal format, but some otheris
written on the memory positions in decimal format. How can I retrieve this
information reading it as decimal?

So far I use this:


#define MYHEXAVAR (uint_16t*(0x200))


//Which would allow me to read data from MYHEXAVAR just declaring it inmy
function. Let's say the position 0x200 of my memory contains 0x0012 as a
value


void myfunc ()

{

sprintf(NewKey, "%3u", *MYHEXAVAR);
memcpy(Key, NewKey, 4);

}





or something similar, I've just outline the function because the real one is
much more complex and long and it wouldn't be good to make my point.
so this func would read memory position 0x200 and write the decimal
representation of 0x0012 which is "18". Now my problem is that I need it to
write "12"
Any of you guys have an idea to how to solve this problem.? It should be
fairly easy, but I don't know whats the easiest. I was thinking about doing
the whole conversion manually reading bit to bit, but I am sure there'ssome
other easier way....


Thanks in advance!

Marc



comp.algorithms question, I believe, but, nevertheless ---

char hextable[] = { '0', '1', '2',
/* you fill in the rest */ , 'D', 'E', 'F'};

step through the bytes(octets?) and output hextable[byte_value];

Worry about endian-ess.
--
Ñ
"It is impossible to make anything foolproof because fools are so
ingenious" - A. Bloch

Nov 14 '05 #3
problem solved! you were right...... I knew it had to be something I
overlooked, as it is clearly specified in the sprinf conversion charts...

Cheers....

Yodai

Nov 14 '05 #4
problem solved! you were right...... I knew it had to be something I
overlooked, as it is clearly specified in the sprinf conversion charts...

Cheers....

Yodai

Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4493
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6102
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
3
9596
by: Tanuki | last post by:
Hi All: I encounter a programming problem recently. I need to read a binary file. I need to translate the binary data into useful information. I have the format at hand, like 1st byte = ID,...
6
3751
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
9
6732
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
21
6357
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing...
4
4213
by: John | last post by:
I need to read data from the file like the following with name and score, but some line may only has name without score: joe 100 amy 80 may Here's my code, but it couldn't read the line with...
10
8333
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
6
3511
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
7128
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...
0
7332
Oralloy
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,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
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...
0
5635
agi2029
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,...
1
5057
isladogs
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...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.