LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

split a decimal number into 2 numbers

Simply change the format specifier constant manually 🙂
0 Kudos
Message 11 of 17
(1,015 Views)
altenbach is correct. The Q&R handles negative numbers in an unexpected way. But this too is easily handled.





There's more than one way to build a cat. Smiley Wink


Message Edited by LabViewGuruWannabe on 11-18-2007 03:18 PM
Download All
0 Kudos
Message 12 of 17
(1,011 Views)

I undestand this is an ancient topic, but for reference, this should be a free implementation

split_fixed_point.png

 

If we're talking pure bitwise split the snippet works. 

 

Regarding negative numbers: in the dual complement, negative numbers can be read as "whole part rounded towards -infinity" + (1 - decimal part):

blazkelbl_2-1755764759738.png

Bitwise split works as intended. Additionally, looking at the split as values: if you add the Whole FXP and Decimal FXP value is equal to FXP value. 

 

 

0 Kudos
Message 13 of 17
(76 Views)

Hi blaz,

 


@blaz-kelbl wrote:

this should be a free implementation


What's "free" in this implementation?

Why go from FXP to bitarray to integer to FXP?

 


@blaz-kelbl wrote:

Bitwise split works as intended.


Sure.

But when working with integers you don't need any bitarrays, use plain boolean operations (AND, OR, shift) instead!

To put it in other words: you only need blue wires!

 

Edit: added the orange way of getting quotient and remainder…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 14 of 17
(68 Views)

I meant free as in uses no resources, but your implementation is actually more elegant and should also use no resources (maybe I missed a post). 

 

The back conversion was just to illustrate. 

0 Kudos
Message 15 of 17
(62 Views)

Hi blaz,

 


@blaz-kelbl wrote:

I meant free as in uses no resources,


This only is valid on LV-FPGA.

In other environments (Win, RT) a bitarray uses way more memory than your underlying FXP datatype (or INT or FLOAT)!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 16 of 17
(51 Views)

Correct, I mistakenly assumed the question was in the context of FPGA

 

(I think I just replied to the incorrect forum post) https://lavag.org/topic/23873-how-to-separate-decimals-and-integers-on-the-fpga-side/

 

Anyway, your solution is best. 

0 Kudos
Message 17 of 17
(44 Views)