Division with some decimal


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Jul 2005
    Location
    Ferrara - Italy
    Posts
    13

    Unhappy Division with some decimal

    Hi to everybody!

    I would have the necessity to perform the following division in PIC Basic, but I don't know from how stings to depart.

    A = B / 5,58

    B is a constant

    I would have the necessity to visualize the result on a display LCD also visualizing 2 decimal.

    Can someone help me?

    Thanks everybody

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darklakebridge7 View Post
    Hi to everybody! I would have the necessity to perform the following division in PIC Basic, but I don't know from how stings to depart.
    A = B / 5,58 B is a constant
    I would have the necessity to visualize the result on a display LCD also visualizing 2 decimal. Can someone help me? Thanks everybody
    You do know that PBP does NOT deal with fractions and decimals...right?

    a var word
    b var word
    'start with a number in b
    1 - b = 655 ' maximum value in b is 655, otherwise word variable b will overflow
    2 - b = b * 100 'shift the decimal point over to right 2 places temporarily
    3 - a = b / 558 'constant value of 5.58 also has it's decimal point shifted over by 2 places

    1 - b = 655 (given)
    2 - b = 65500 (closest you can get without overflowing a word value)
    3 - a = 117 ( 65500 / 558, PBP doesn't do fractions)

    Do a search on 'decimal' and 'fraction' here and you'll find some stuff. Otherwise, download the floating point math routines from microchip if you need good accuracy.
    Last edited by skimask; - 7th May 2007 at 20:31.

  3. #3
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Wink

    While B is a constant,
    just type it to your desktop-calculator and place the result inside a LCDOUT-command. ;-)

    Because, if B is a constant and 5,58 too - the result "A" is another constant. You don't need any calculation in runtime...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BigWumpus View Post
    While B is a constant,
    just type it to your desktop-calculator and place the result inside a LCDOUT-command. ;-)

    Because, if B is a constant and 5,58 too - the result "A" is another constant. You don't need any calculation in runtime...
    Oh..Hey...Good point!
    Missed that entirely! DOH!
    That really would save a lot of calculation time wouldn't it...

  5. #5
    Join Date
    Jul 2005
    Location
    Ferrara - Italy
    Posts
    13


    Did you find this post helpful? Yes | No

    Unhappy

    Hi boys!

    I have been wrong to expose the problem!

    I would have the necessity to divide the variable "B" for the number 5,58 and subsequently to visualize the result "A" on LCD.

    My very problem is the following:

    A = B / 5,58

    Excuse the error! Everybody can help me??

  6. #6
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Not knowing the size of B, I've used DIV32. B can be any integer up to 65534.

    A VAR WORD
    B VAR WORD


    A = B * 100 'A is temporary storage of computation
    A = DIV32 558 'using DIV32... B can be any integer up to 65534
    A = A / 100 'final result is placed in variable A as an integer... any
    'remainder will be discarded.

    Hope this helps,

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  7. #7
    Join Date
    Jul 2005
    Location
    Ferrara - Italy
    Posts
    13


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by rossfree View Post
    Not knowing the size of B, I've used DIV32. B can be any integer up to 65534.

    A VAR WORD
    B VAR WORD


    A = B * 100 'A is temporary storage of computation
    A = DIV32 558 'using DIV32... B can be any integer up to 65534
    A = A / 100 'final result is placed in variable A as an integer... any
    'remainder will be discarded.

    Hope this helps,

    Ross
    Thank you Ross!

    Thanks for your fast answer!

    The routine works, but I would have the necessity to visualize on LCD the data drawn with 2 decimal.

    Would you know how to help me?

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Tip: use DIG and DEC modifier with LCDOUT.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Tip: use DIG and DEC modifier with LCDOUT.
    And of course...read the manual...

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    And of course...read the manual...
    You know....

    I've refered to the "Manual" several hundred times by now.
    Usually, I'm trying to answer a specific question. (not always successfully)

    The fact that I keep having to look at it, either means I'm Stupid, or you can't grasp the wealth of knowledge from (a couple hundred views)

    Just because you read it, doesn't mean you understand it.

    That's what the forum (and us giver's) are here for!

    To fill in the gaps.

    In other words skimask,
    from DT
    "Cut the RTFM crap".
    DT

  11. #11
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Talking Regarding DT's reply

    Code:
    IF READING = COMPREHENDING THEN
    BE A BOSS YOURSELF
    ELSE
    GOTO THE FORUM AND ASK FOR SUPPORT
    ENDIF
    Regards

    Sougata

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darklakebridge7 View Post
    A = B / 5,58
    Now then, where were we?

    Darklakebridge7,

    An easy way to think about it is to look at how you would "Name" the numer.

    For instance,

    5.58 is 558 hundredth's of whatever it is.

    So if you multiply by 558, then divide by 100 (hundredths), you end up with the correct answer. (integers only)
    Code:
    B = 123
    A = B * 558
    A = DIV32 100
    Piece of Pie, or was that cake.
    DT

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Jeeze...you (not You D_T,but a person in general) pay good money for a product (any product will do), it comes with a manual or maybe a sheet of directions, a playbook, something. The PBP package even comes with examples here and there, heck, it practically comes included with this website, complete with a working search engine, not to mention over 78,000 hits on Google just by typing in "PicBasic Pro" (in quotes) as the search parameter.
    The one thing I don't see included with the PicBasicPro package is a whole bag of lazy, because when I look at my posts, the majority of the time where I mention 'RTFM', the answer is right there, black and white, page after page of good info, not to mention the vast availability of resources on the 'Net. And 'lazy' is what I see when the answer is right there on paper in the manual. I see it everyday at work, and I use the same answer to my subordinates, superiors, and laterally across the different shops. If the answer is right there, read the book. I've been using that phrase since I took over my shop a little over 7 years ago and I think my guys in my shop (as well as the others) are a heck-of-a-lot smarter because of it (mainly because sometimes they keep reading past the area that I pointed them to in the first place).
    The fact that you have to keep referring to the manual to find answers tells me that the manual already had the answer to begin with.
    I've got no problem helping a guy figure out the wierd stuff, things that aren't 'right there in front of you'...but the blatently obvious...?
    And the reference to the manual in the last post relating to DEC and DIG. No, the manual doesn't say anything about decimal points and getting the tenths/hundreths digits to show up on the LCD. But...couldn't a guy use a bit of inductive reasoning and figure out how to use that modifier and that function to do his bidding on the LCD?
    Has or Is inductive reasoning (for that matter deductive reasoning) gone the way of the DoDo bird? It all rolls right back to that 'feed a man a fish' thing.

  14. #14
    Join Date
    Jul 2005
    Location
    Ferrara - Italy
    Posts
    13


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by Darrel Taylor View Post
    Now then, where were we?

    Darklakebridge7,

    An easy way to think about it is to look at how you would "Name" the numer.

    For instance,

    5.58 is 558 hundredth's of whatever it is.

    So if you multiply by 558, then divide by 100 (hundredths), you end up with the correct answer. (integers only)
    Code:
    B = 123
    A = B * 558
    A = DIV32 100
    Piece of Pie, or was that cake.
    Hi to everybody!

    Forgive me, but I am new and I have some problem with the language English! Could you recommend me a some good book of PIC Basic?

    A special thanks to all those people that have helped me to resolve my problem!

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    No need for a book! Forum and head-banging is more than enough!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    A VAR WORD
    B VAR WORD
    TNTH VAR BYTE
    HUNDTH VAR BYTE


    A = B * 100 'A is temporary storage of computation
    A = DIV32 558 'using DIV32... B can be any integer up to 65534
    TNTH = A DIG 1 'GRAB THE "TENS" DIGIT FROM "A"
    HUNDTH = A DIG 0 'GRAB THE "ONES" DIGIT FROM "A"
    A = A / 100 'final result is placed in variable A as an integer... any 'remainder will be discarded.

    LDCOUT $FE,1 'CLEAR DISPLAY
    LCDOUT "A = ",#A,".",#TNTH,#HUNDTH

    I think that would give you what you want.

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

Similar Threads

  1. variable + decimal
    By savnik in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th August 2009, 14:21
  2. Binary Coded Decimal
    By -Dan- in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th May 2009, 09:23
  3. 16bit variable and degrees conversion
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd May 2005, 17:27
  4. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 20:05
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts