BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Wed Nov 21, 2018 2:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: More help please with a few things
PostPosted: Wed Jul 20, 2011 10:30 pm 
Offline
Citizen

Joined: Sat May 07, 2011 9:52 pm
Posts: 30
I know some of this stuff should be easy but I think my brain is fried. Ok, I have two issues. First I have a EEPROM that has some data stored in it. For simplicity let's just say the first 4 bytes are what I am interested in, and contain the following values in this order:

49
16
00
00

Now, this represents the decimal number 00001649 (1,649 with some leading zeros for when the number grows). Now the first problem I am having is since the numbers are already stored in decimal form, how do I display them in a terminal window or on a LCD? I'm using a line like this, where 'promin' is the value I read from the EEPROM. But the dec command wants to assume it's in hex format and convert it. If I leave off the dec command, it doesn't work.

serout s_out, i38400, [dec address," This memory location = ",dec promin, 13]

Next, I need to actually take those 4 bytes and put them together to make the actual number 1649.

Actually I don't need to display the individual bytes as long as I end up with a variable that has the number 1649 in it. But I would still like to know to how do it. Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: More help please with a few things
PostPosted: Wed Jul 20, 2011 11:23 pm 
Offline
Citizen

Joined: Sat May 07, 2011 9:52 pm
Posts: 30
Ok, I figured out that I can use the ISHEX command to be able to display the actual contents of the the memory locations. But I still don't know how to make the program know that those are actually decimal numbers. And I'm still at a loss as to how to put it all together to make it a real number. Many years ago when I was using a Basic Stamp, I recall doing something similar where you could convert the numbers into a text string, put it all together and then convert it back into a number. I can't seem to find any similar commands.


Top
 Profile  
 
 Post subject: Re: More help please with a few things
PostPosted: Thu Jul 21, 2011 12:31 am 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Yep you can use ISHEX. When I want hex I usually don't want signed so I just use HEX ...

If you have a long 32 bit value lets say: foo var long
And you wish to read it all in from EEPROM and the data is stored in the right order you can do this like:
READDM [0, str foo\4]

or:

If they are in the wrong order you can try something like:
READDM [0, foo.byte0, foo.byte1, foo.byte2, foo.byte3]

Don't remember which order the byte order is in the command so you may need to reverse.

or

You can read them each into different variables and build it
READDM [0, b0, b1, b2, b3]
assuming the b0, b1, b2, b3 are defined
foo = (b3 << 24) | (b2 << 16) | (b1 << 8) | b0

could use + instead of |. Could use array...

Kurt


Top
 Profile  
 
 Post subject: Re: More help please with a few things
PostPosted: Thu Jul 21, 2011 1:05 am 
Offline
Citizen

Joined: Sat May 07, 2011 9:52 pm
Posts: 30
Thanks, but I still have a problem with actually using the numbers as they are stored. After thinking about it, it's actually quite simple to put it back together. If I take the following bytes

49
16
00
00

and then do some simple math

49 + (16 x 100) + (00 x 10,000) + (00 x 00,000) = 1649

BUT, the problem is I don't know how to treat those digits as decimal numbers to begin with.

So somehow I need to take the value 49 (even though it's really a hex number since it's stored in memory) and convert it to the decimal number 49. Maybe it's not possible.

BTW, the data is stored in that format by another piece of equipment, so I can not change it, and have to use it like it is.


Top
 Profile  
 
 Post subject: Re: More help please with a few things
PostPosted: Thu Jul 21, 2011 7:22 am 
Offline
Citizen

Joined: Sat May 07, 2011 9:52 pm
Posts: 30
Ok, I got it figured out with some help from another guru. Just use the high and low nibbles to get the decimal equivilent of the hex number. So for byte 1 which is hex 49 (but I need decimal 49) I just do:

decimalbyte= byte1.highnib * 10 + byte1.lownib

and I get 49. I do the same for the other 3 bytes and then do the math to put it all together. I knew this had to be easy. :lol:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO