How to display large numbers


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    67

    Question How to display large numbers

    Hi,

    I have used the 32 bit asm multiply routine and have got a number larger than 16 bits (of course!!)

    Now i want to display this number but it wont !!

    OK..

    The number is 317440

    The numbers displayed are

    4 55296

    4 is the high byte number = 262144
    55296 is the low byte number = 55296

    add these togheter you get 317440, correct answer but wrong display...

    debug #(hibyte), # (lobyte)

    any suggestions ?

    thnks

    Pete
    Pete

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Interesting problem ... although there must be a cleaner way, the below works for YOUR specific numbers. The below is not ready for plug and chug with any double word but should help YOU get headed in the right direction. Fun stuff!

    Lo_word var word
    Hi_word var word
    X_temp var word

    Digs var byte [6]

    Lo_word = 55296 ' Low word
    Hi_word = 4 ' High Word (= 4 * 65536)

    '**************************
    'Find 3 low digits of your 6 digit decimal number

    X_temp = Hi_Word * 536 + Lo_word ' = 57440

    ' take 4*65536+55296 = 4*(6200+536)+55296 = 4*62000+4*536+55296
    ' the 4*62000 term does not contribute to the low 3 digits so leave it out

    Digs[0]=X_temp Dig 0 ' = 0
    Digs[1]=X_temp Dig 1 ' = 4
    Digs[2]=X_temp Dig 2 ' = 4

    '**************************
    'Find 3 High digits of your 6 digit decimal number

    X_Temp = Hi_Word * 2 ' = 8
    X_Temp = 32768 * X_temp ' = 262144
    X_Temp = Div32 100 ' = 2621
    X_Temp = X_temp + (Lo_word/100) ' = 3173

    Digs[3]=X_temp Dig 1 ' = 7
    Digs[4]=X_temp Dig 2 ' = 1
    Digs[5]=X_temp Dig 3 ' = 3

    '**************************
    'Display (change to meet your needs)

    ' for X_temp = 5 to 0 step -1
    ' Debug Dec Digs[X]
    ' next X_temp

    END

    Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Red face

    Opps - on the comment in the above code snippet ....

    is:
    ' take 4*65536+55296 = 4*(65000+536)+55296 = 4*65000+4*536+55296
    ' the 4*65000 term does not contribute to the low 3 digits so leave it out

    was:
    ' take 4*65536+55296 = 4*(6200+536)+55296 = 4*62000+4*536+55296
    ' the 4*62000 term does not contribute to the low 3 digits so leave it out


    I need more coffee - paul

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


    Did you find this post helpful? Yes | No

    Default

    OK,

    32-bit-arithemtik,
    sometimes I'm happy to have learned the basics of our job (on a pdp/8 with 12-bit-words an silly switches and lamps on the front).

    Div-by-10 ... uuuh ... I feel sleepy!

    $7FFFFFFF is decimal 2147483647 .... uuuh, the big one !

    I think, you will deal with 7-count numbers....
    Just look, if the number is bigger then 999999:

    Flag=0
    if High_Word>$F Then Flag=1
    if High_Word=$F AND Low_Word>$423F Then Flag=1

    If it is bigger, count how often by subtracting 1000000 !

    Ct=0
    If Flag Then
    Repeat
    If Low_Word<$4240 Then High_Word=High_Word-1
    Low_Word=Low_Word-$4240:Ct=Ct+1
    [...] copy **** from above
    Until Flag=0
    Endif

    You got an digit ! Just Store or print it ! (LCDWRITE "0"+Ct)
    Multiply the rest by 10 !

    Gosub Rotate32 (x2)
    High_Copy=High_Byte:Low_Copy=Low_Byte
    Gosub Rotate32:Gosub Rotate32 (all together x8)
    High_Word=High_Word+High_Copy
    If Low_Word.15 AND Low_Copy.15 Then High_Word=High_Word+1:Low_Word.15=0:Low_Copy.15=0
    Flag=Low_Word.15 or Low_Copy.15
    Low_Word=Low_Word+Low_Copy:If Flag AND (Low_Word.15=0) Then High_Word=High_Word+1

    Rotate32:
    High_Word=High_Word<<1:If Low_Word.15 Then High_Word.0=1
    Low_Word=Low_Word<<1:Return

    uuuuh ... with assembler its much smoother because of the carry-flag.


    Repeat it seven times !
    Go sleep!
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Similar Threads

  1. Hdsp 21xx display
    By Original in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th June 2012, 20:07
  2. LARGE 40x4 LCD Display
    By Art in forum Adverts
    Replies: 3
    Last Post: - 15th December 2008, 09:19
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. store/display very large numbers (700000)
    By ttease in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th March 2007, 22:08
  5. Multiplying large numbers
    By jhonea1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2006, 17:41

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