
adccommunitymod (AutomationDirect) asked a question.
Converting 32 bit binary number to Real
Created Date: August 10,2011
Created By: plcman
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
Hi Has anybody convereted 32 bit signed binary values to Real numbers in a DL260 cpu, any help would be gratefully recieved. :confused:
Created Date: August 10,2011
Created by: bcarlton
The BTOR instruction's information in the manual says
The Binary to Real Number instruction converts the 2's complement binary value in the accumulator into a 32 bit real number. The result resides in the accumulator.
That would seem to imply that it would handle it. Have you tried it?
Created Date: August 10,2011
Created by: plcman
The BTOR instruction's information in the manual says
That would seem to imply that it would handle it. Have you tried it?
Thanks for that. Yes I had tried it. It only converts 16 binary bits and doesn't seem to handle the sign, any other ideas?
Created Date: August 10,2011
Created by: Bob S BN
Yes I had tried it. It only converts 16 binary bits and doesn't seem to handle the sign, any other ideas?
How are you checking for the value? DataView?
Do you have the address set to display double word?
Just a thought,
Created Date: August 10,2011
Created by: plcman
How are you checking for the value? DataView?
Do you have the address set to display double word?
Just a thought,
Bob
Yep in the dataview and I have it on DWord.
Though the BTOR obviously ouputs to a double word (as with all real numbers) it only loads one word and doesn't seem to recognize the MSB as the sign.
Created Date: August 10,2011
Created by: JoeW
You are doing a LDD> BTOR correct? As for your negative values, are you using 2s compliment or sign+magnitude?
Created Date: August 10,2011
Created by: bcarlton
Just tested on a DL06. Up to 32 bits converted ok but MSB not interpreted as a sign. Always get a positive result.
Created Date: August 10,2011
Created by: plcman
You are doing a LDD> BTOR correct? As for your negative values, are you using 2s compliment or sign+magnitude?
Hi
Once I had taken the mixer out of my brain, I have got it working using BTOR and 2 'complement.
I was looking for a far more difficult solution, this way is far too easy.
Thanks all!:D
Created Date: August 10,2011
Created by: plcman
Just tested on a DL06. Up to 32 bits converted ok but MSB not interpreted as a sign. Always get a positive result.
In my example, I am converting v3000 from 32 binary to real so I check if b3001.15 is on and if so multiply the real number by -1.
Created Date: August 10,2011
Created by: bcarlton
Reset a bit - let's say C0
If B3001.15 is ON then set C0 AND reset B3001.15
Do BTOR on V3000 - OUTD to real location
If C0 is on then multiply real by -1
Created Date: August 10,2011
Created by: bcarlton
Assuming you are using a twos complement version of your number
Reset a bit - let's use C0
If B3001.15 is NOT On then LDD V3000 - OUTD some other double V register
If B3001.15 is ON then
set C0
LDD V3000
INV - creates a 'ones complement '
ADDB K1 - creates a 'twos complement ' or positive version of the same number
OUTD - other double V register
LDD other double V register
BTOR
OUTD Real location
If C0 is on the MULR Real Location by -1
-------------------------
If you are using sign plus magnitude then
if top bit is set remember it in C0
turn off top bit
BTOR what remains
if C0 is on then multiply result by -1