LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to Decimal convert in reverse manner.

Solved!
Go to solution

Dear all,

 

I have a binary data set which I want to convert using negative powers of two. For example I have a binary data

11101100100000000000000

 

which I want to convert in decimal using method below ( negative powers of two).

(1 * 2^-1) + (1 * 2^-2) + (1 * 2^-3) + (0 * 2^-4) + ... + (0 * 2^-23).

I have been successful till the part or reversing the whole data set but couldn't figure out the rest. Help is sorely needed. 


Regards.


0 Kudos
Message 1 of 32
(6,892 Views)
Solution
Accepted by topic author NapDynamite

Hi Nap,

 

you can do that bit by bit - or with the whole number in just one step:

check.png

Edit: I added one possible "hard way bit by bit" solution as well..

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 32
(6,883 Views)

Dear GerdW,

Thanks alot 🙂

Regards.


0 Kudos
Message 3 of 32
(6,874 Views)

A simpler way would be to use the Reverse String function and then use the Scan From String with the %b format.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 32
(6,855 Views)

Dear crossrulz,

I tried your suggestion but I wasn't getting required result. I reversed the string and fed it into the scan from string block with the %b format. I couldn't get the value as I would get by trying the above mentioned suggestion. 

Or may be I didn't understand your suggestion properly. 

Regards.


0 Kudos
Message 5 of 32
(6,834 Views)

Sounds like a job for Integer to fixed point cast:

 

toFxp.png

Message 6 of 32
(6,827 Views)

@NapDynamite wrote:

Dear crossrulz,

I tried your suggestion but I wasn't getting required result. I reversed the string and fed it into the scan from string block with the %b format. I couldn't get the value as I would get by trying the above mentioned suggestion. 

Or may be I didn't understand your suggestion properly. 

Regards.


Nope. I misinterpreted something.  Sorry.

 

That integer to fixed point is a nice trick!



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 32
(6,808 Views)

That would be a Binal (or what you should call the fractional part of a binary number), so simply do binary string to number and divide by 2^string length. (which is the top part of Gerds solution ^^)

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 32
(6,786 Views)

@GerdW wrote:

 

Edit: I added one possible "hard way bit by bit" solution as well..


The hard way can be made quite a bit less hard, e.g. as follows. 😄

 

It is probably pretty fast (not tested, though).

 

 

0 Kudos
Message 9 of 32
(6,776 Views)

Dear Willd,

I have a little difficulty knowing the purpose of constant defined that is connected to fixed-point type. This is the first time I'm using this function. Why do we have to change the encoding of this constant to unsigned, word length to 23 bits and integer word length to 0 bits? A little explanation would be appreciated so I could get a better understanding for problems in future. 

 

 

 

 

 

Fixed point type.png 

 

 

Regards.


0 Kudos
Message 10 of 32
(6,753 Views)