08-19-2009 12:57 AM
smercurio_fc wrote:
. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").
Well, in my program every number of the string is intrepreted as HEX. So if it is 45, then the byte that I want is 0x45.
08-19-2009 01:50 AM
08-19-2009 02:17 AM
Hi GerdW,
I have done this as well but in a little bit more complicated way. The question that I have is that how to write this command in a binary file so that when I send it the program knows that this is hex and nothing else.
Thanks a lot
Iliya
08-19-2009 02:43 AM - edited 08-19-2009 02:43 AM
Hi igurov,
see attachment for saving to file. Rather simple and straightforward...
"the program knows that this is hex and nothing else"
Which program? If it's your vi then you have to ensure this. Maybe using some headers? Making your own file format? Using config files?
08-19-2009 08:48 AM
GerdW,
You could simplify your conversion by doing a hex string to number instead of decimal, then the output is the number you need; no bit twiddling needed!
Or..... Inside the loop use scan from string with format %2x. The value output is the array element, the string output feeds back to the next iteration via a shift register. [Use either a for loop with N=6 or a while loop terminating on string output is zero length] Now you don't need a separate part of the loop to extract the required segment of the input string.
(Sorry can't post files!)
Rod.
08-19-2009 08:58 AM
igurov wrote:I know exactly what the difference between decimal and hex is!? But I am not sure whether you understand what I really want.
I have a specific requirements and mainly that I have to write the string of date/time as hex value in a file and then send it via serial connection. Please, tell me, where in the whole story sth does not make sense to you.
The fact that, as has been pointed out, you are actually talking about BCD, not HEX. Treating a BCD number as HEX is simply not correct, as they are two different numbers. But then, you already knew that, right?
08-19-2009 09:01 AM
Hi Rod,
thanks for advice!
The "hex string to number" would fit fine here. My calculation is the more general way (when just providing an array of numbers).
"Use either a for loop with N=6 or a while loop terminating on string output is zero length"
Well, at the moment I'm checking for "less than 2", which is more error-safe in case of odd-length strings
08-19-2009 09:49 AM
GerdW wrote:
My calculation is the more general way (when just providing an array of numbers).
...... checking for "less than 2", which is more error-safe in case of odd-length strings
Of course, yes. My suggestion was very specific to this particular case. I was assuming correct input as there was no user-influence upon it. But we all (should) know how correct user input is.
07-01-2011 10:07 AM
@smercurio_fc wrote:
Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").
smercurio_fc, i have the same requirements as you mentioned in the above post... and the code you posted here, should suffice my requirements, but a question... why did you subtract 2000 from YEAR in your vi?
07-05-2011 08:58 AM
@CrackJack wrote:
@smercurio_fc wrote:
Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").smercurio_fc, i have the same requirements as you mentioned in the above post... and the code you posted here, should suffice my requirements, but a question... why did you subtract 2000 from YEAR in your vi?
To get a 2-digit year. That was part of the original format.