LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert a Decimal Numeric to Hex String of 2 BYTES

Solved!
Go to solution

Hello..

 

I need to convert numeric value ranging from 0 to 2014 and convert it to 2 Byte HEX STRING.

 

Example;

 

Decimal : 1              --> Hex - 0001 

Decimal : 255         --> Hex - 00FF 

Decimal : 512         --> Hex - 0200

 

 tried but its working till 511 only.

Please Help.

VI is attached.. 

0 Kudos
Message 1 of 20
(8,162 Views)
Solution
Accepted by topic author Nayan

Hi Nayan,

 

why don't you post all your "convert from x to y" questions in just one thread?

 

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 20
(8,146 Views)

I thought those were different topics..

Anyways, Thank you very much. I had so much work today, U helped me a lot in previous posts also.

Thanks..

0 Kudos
Message 3 of 20
(8,132 Views)

Hi Nayan,

 

when you have such question more often you should learn how numbers are represented/stored in computer memory!

 

The solutions I have shown you are very basic conversions, suitable just for exactly the case you asked for. There are other ways to convert your data and yo will learn them once you gain some more understanding of these representations…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 20
(8,127 Views)

Thanks for your suggestestion GerdW.

0 Kudos
Message 5 of 20
(8,105 Views)

Hi again..

 

Again the conversion part...

I have a 11 byte hex string. I want to save this hex string in some file if I click save button.

Again next time on clicking save button, it should be be appended.

 

Then I have to regain the hex string from that file.

 

Any Guidence Please?

0 Kudos
Message 6 of 20
(8,081 Views)

Gerd's solution above is overly complicated. All you need is a typecast operation if you use a 2byte datatype (e.g. U16). Same result. (see image)

 

 


Nayan wrote:

Again the conversion part...

I have a 11 byte hex string. I want to save this hex string in some file if I click save button.

Again next time on clicking save button, it should be be appended.


This is not a "conversion" question. A file is basically just a long string too.

 

Just write the string to a file without modification.

 

Note that if you append string to an existing file, the fil will grow with each operation and it will contain several 11 byte strings.

 

To read it you can either read the entire file, then chop it up into strings of lenght 11 or you can calculate the file offset (a multiple of 11) and read 11 bytes. If you want to read the last 11 bytes, calculate the offset from the file size.

 

 

Show is some code attempts if you need further help.

Download All
Message 7 of 20
(8,052 Views)

Hi Christian,

 

my aim wasn't to show the simplest code, but to show code that helps to understand the conversion asked for.

So in this case

- how to get single bytes from an U16 integer

- how to build an array of bytes

- how to convert an array of bytes to a string

Typecasting is some kind of magic to new LabVIEW users (or people having done no programming at all so far), so I chose the step-by-step approach.

 

And I also wrote "There are other ways to convert your data…" for a reason!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 20
(8,012 Views)

GerdW wrote:

And I also wrote "There are other ways to convert your data…" for a reason!


Ah, OK, but that was in a later post... 😉

 

There is nothing wrong with introducing the typecast (or flatten to string) operation. At one time they need to learn i anyway and here it directly illustrates what it does in the simplest possible way.

 

(I think your posted solution is equally confusing to the new users, because it includes "split number" and the concept of arrays, for example. :D)

0 Kudos
Message 9 of 20
(8,005 Views)

Thankyou both for your replies. I am a rookie in Labview and so many things to learn from you guys.

 

Again I have got a question.

I have a string array. Initialy it is empty and I want to fill it with a unique index each time.

Here in this vi (attached), I have used 'insert into array' function.

The array is getting updated.

 

I initiated the array with '0' index first.

But if I am putting index as '0' next time, it should have to update the value of index 0 only, but it is getting the value at index 0,1,2,3...

 

what should I use to overcome this??

 

0 Kudos
Message 10 of 20
(7,898 Views)