06-06-2024 12:52 AM
Hi,
I am looking for Decimal to binary conversion Vi.
06-06-2024 01:10 AM - edited 06-06-2024 01:48 AM
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:
06-06-2024 07:28 AM
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
06-06-2024 09:53 AM - edited 06-06-2024 09:54 AM
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
What is binary in your case?
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.
06-06-2024 01:52 PM
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.)
06-06-2024 01:56 PM
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.
06-06-2024 04:08 PM - edited 06-06-2024 04:09 PM
@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. 😄