LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: decimal number to binary conversion using for loop

Hi,

I am looking for Decimal to binary conversion Vi.

0 Kudos
Message 1 of 7
(624 Views)

Hi shradu,

 


@shradu wrote:

Hi,

I am looking for Decimal to binary conversion Vi.


What is the required output data?

Can you share an example of expected result for any given input?

 

Hint: "decimal" and "binary" is just a different formatting for the very same numeric value…

 

Simple example:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(616 Views)

When you were in high school and took Algebra, did you learn about Number Bases (i.e. what "10" means in decimal notation, and how to express it in binary)?  Take a piece of paper and a pencil and work out the binary conversion of 19, then think about the steps you took, the decisions you made, and "do it in LabVIEW".

 

Bob Schor

0 Kudos
Message 3 of 7
(565 Views)

Is using a FOR loop a requirement?

 

Your definitions are very vague and insufficient to solve the problem. I can guaranteed the under the hood everything (everything!!!) is binary, because that's how computers work. Right?

 

What is decimal in your case

 

  • A long string of characters exclusively 0..9?
  • A numeric blue unsigned integer set to decimal display?
  • Something else?

What is binary in your case?

 

  • a long string of characters exclusively 0 or 1?
  • an numeric blue integer with a binary display format?
  • A boolean array? An array of numbers 0 or 1?
  • Is the LSB left or right?
  • something else?

 

Depending on the problem you are trying to solve, things might need no code at all. if you absolutely are required to use a FOR loop, things become very slightly more complicated.

0 Kudos
Message 4 of 7
(542 Views)

If you are trying to just see the binary representation of an integer, right click on the indicator and go to Properties, > Display format, and choose "Binary". (Note this can't be with the default numeric type, which is a Double.)

 

binary.png

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 5 of 7
(522 Views)

BTW, Bob Shor's advice is not helpful, since usually such conversions don't have to be written from scratch. Sure, you could do it, but that would be wasting time. To be honest, I wrote a binary converter myself years ago because I didn't know it was a native function.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 6 of 7
(519 Views)

@littlesphaeroid wrote:

Sure, you could do it, but that would be wasting time.


 

Well, a FOR loop is apparently a requirement as hinted in the subject line, thus doing explicit math seems to be needed. However, since we don't know the type of input and output, we cannot help at this time.

 

It still would be a good exercise to make a universal solution that can handle from/to any base. (e.g. quinary to vigesimal and back) 😄

 

Here's another requirement that could be added: convert binary to decimal wile tapping head and rubbing the belly. 😄

0 Kudos
Message 7 of 7
(510 Views)