LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"Reverse" bytes in string

@RobertoBozzolo you should swap only half of "duplets", not all of them. I did not test your code, but I believe it returns an untouched string...

 

 

Carlo A.
Megaris




0 Kudos
Message 11 of 15
(488 Views)

Nope: the code handles half of the string and returns the inverted string as desired (the combination of duplets and i += 2 does this). It could be furterly optimized in case of an odd number of duplets to skip the middle duplet, which is actually swapped on itself, but the final result is the expected one.

 

My code in effect is not so different from yours if you consider len2 <=> duplets...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 12 of 15
(478 Views)

@RobertoBozzolo It is a real shame that posts cannot be deleted on this forum. I overlooked the number of swaps your code does.

Just to get some credibility back 🤣, the case of an odd number of duplets is managed in my code by the otherwise unuseful division by four and multiplication by two, avoiding swapping a duplet with itself.



Carlo A.
Megaris




0 Kudos
Message 13 of 15
(467 Views)

Aha! That's why you put it there!

The smile was not enough for me to understand it!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 14 of 15
(463 Views)

@BlueAnaconda wrote:

Hello,

 

I have a string like this : "ABCDEF"

I want to get this from this string : "EFCDAB".

 

What's the best way to do that in CVI ?


Are you sure this is about a string and not simply an integer displayed as hexadecimal number? Adding a character from outside the range A -F would have helped to avoid this ambiguity. 😉

 

It's definitely not a CVI specific problem but simply a standard programming algorithm question that applies to any possible programming language out there.

Rolf Kalbermatter
My Blog
0 Kudos
Message 15 of 15
(439 Views)