Converting 32 bit Floating Point, and 48 and 64 bit Integer to string


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Converting 32 bit Floating Point, and 48 and 64 bit Integer to string

    I think that I solved this...
    From include file FP32.A18:
    Code:
    ;       32 bit floating point representation
    
    ;       EXPONENT        8 bit biased exponent
    
    ;                       It is important to note that the use of biased exponents produces
    ;                       a unique representation of a floating point 0, given by
    ;                       EXP = HIGHBYTE = MIDBYTE = LOWBYTE = 0x00, with 0 being
    ;                       the only number with EXP = 0.
    
    ;       HIGHBYTE        8 bit most significant byte of fraction in sign-magnitude representation,
    ;                       with SIGN = MSB, implicit MSB = 1 and radix point to the right of MSB
    
    ;       MIDBYTE         8 bit middle significant byte of sign-magnitude fraction
    
    ;       LOWBYTE         8 bit least significant byte of sign-magnitude fraction
    
    ;       EXPONENT        HIGHBYTE        MIDBYTE         LOWBYTE
    
    ;       xxxxxxxx        S.xxxxxxx       xxxxxxxx        xxxxxxxx
    
    ;                        |
    ;                      RADIX
    ;                      POINT
    IeeFormat:
    http://www.h-schmidt.net/FloatConverter/IEEE754.html
    As you can see in IEE format, only 7 bit of exponent is in first byte, so bit 23 should be shifted to first bit of byte3, when shifting to right exponent.
    Here is binary for 23.75:
    Code:
    IEE   41BE0000 = 01000001 10111110 00000000 00000000
    MCHIP 833E0000 = 10000011 00111110 00000000 00000000
    Darel 82BE0000 = 10000010 10111110 00000000 00000000
    As you can see Darrel's code set sign instead of first bit of exponent.
    Here is my code, done in PBP
    Code:
    MyIEEEtoMCHIP:
        B.BYTE0=A.BYTE0
        B.BYTE1=A.BYTE1
        B.BYTE2=A.BYTE2 : B.23=A.31 'SIGN
        B.BYTE3=A.BYTE3<<1 : B.24=A.23
    RETURN
    A-IEEE 
    B-Microchip
    I'll try to fix Darrel's macro.

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Converting 32 bit Floating Point, and 48 and 64 bit Integer to string

    I fixed bug in Darrel's macro:
    Code:
    ASM
    IEEEtoMCHIP?NN  macro Nin, Nout
        MOVE?BB Nin, Nout
        MOVE?BB Nin+1, Nout+1
        MOVE?BB Nin+2, Nout+2
        ;MOVE?TT Nin+3,7, Nin+2,7  ;<<<<<<<<here he is setting bit in input byte, not output byte
        MOVE?TT Nin+3,7, Nout+2,7  ;<<<<<<<<Corrected
        MOVE?BA Nin+3
        RLNCF   WREG,W
        MOVE?AB Nout+3
        MOVE?TT Nin+2,7, Nout+3,0
      endm
    ENDASM

Similar Threads

  1. Using Floating Point to integer subroutines
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 5th March 2014, 08:52
  2. Microchip 32bit floating point to integer conversion
    By timmers in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st February 2011, 17:49
  3. Replies: 5
    Last Post: - 28th May 2008, 11:20
  4. Replies: 3
    Last Post: - 18th March 2008, 05:29
  5. Floating Point Display Problem (serial string out)
    By Cash Olsen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th December 2007, 03:03

Members who have read this thread : 0

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