02-13-2024 06:07 AM
Both do the same and work binary. If you want to do BCD logic then that is an entirely different topic. But the examples in the first post are not really BCD either. A byte value of 50 decimal is not BCD!
02-13-2024 09:17 AM
This recreates your example without the bitwise issues.
02-13-2024 01:45 PM
@Ben_Manthey wrote:
This recreates your example without the bitwise issues.
While it is certainly possible that some hardware, somewhere, under some strange circumstances requires this sort of conversion, I would argue that it is pretty stupid. BCD numbers (where decimal digits are encoded in 4 bits each) are already kind of weird nowadays although they were quite common in the 70ies of last century for pocket calculators) but this would simply be at least one magnitude weirder.
02-14-2024 06:11 AM
02-14-2024 03:35 PM - edited 02-14-2024 03:42 PM
@Rajsakthi wrote:
I have an array of four elements as a numeric value. Lets take element 1 is 90 and element 2 is 50 and element 3 is 70 and element 4 is 60 i need an output as reverse of first two elements result should be 5090 and another one is 6070.if anyone have some suggestions let me know it will be helpful.
Obviously, the quality answer can often not exceed the quality of the question, and your question is quite ambiguous.
It also helps to give some context, for example explain what the number represent and where they come from.
You don't say what the display format of your numeric values are, for example 90 (decimal) is not the same as 90(hexadecimal), but the suitable answer critically depends on it.
You also don't define what should happen in the input array has an odd number of elements (truncate or pad?).
Here are solutions to two possible interpretations of the question, one for each display format: Both will drop the last element if the input has an odd number of elements. Note that all controls/indicators show the radix for clarity.
Obviously, U8 can have values from 0..255 (or 0..FF in hex). For the decimal solution you would also need to define what should happen if input values are above 99, if that is a possibility (create error? create a 6 digit output? something else?).