473,666 Members | 2,102 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*(0x20 0))
//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 2955
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*(0x20 0)) //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.hel sinki.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*(0x20 0))


//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
4519
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
6135
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
3
9613
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, next 4 byte (int) = serial number etc. The first problem is Big Endian/ Little Endian problem. I can decipher if the format is big or little endian. But got confuse as to how to decipher the data.
6
3785
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 trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
9
6750
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
21
6380
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 this (it's only a test trying to achieve the goal...):
4
4227
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 "may" because there is no score. Anyone knows what is the workaround to this problem?
10
8347
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 delivery of Travis Oliphant's NumPy manual, I have a quick question (hopefully) regarding how to read in Fortran written data. The data files are not binary, but ASCII text files with no formatting and mixed data types (strings, integers,...
6
3524
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 to an old program that I wrote in delphi and it's a good opportunity to start with c++.
0
8449
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8360
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8876
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8556
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8642
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1777
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.