View previous topic :: View next topic |
Author |
Message |
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Wed Apr 15, 2020 3:33 pm Post subject: HEXVAL |
|
|
Is there a simple way to verify that the string that I am converting using HEXVAL
contains legitimate hex characters (0-9, A-F, a-f) without testing to make sure each
character falls into one of those three ranges?
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Apr 15, 2020 5:01 pm Post subject: |
|
|
Quote: | ...you can use the alternative library named hexval.lbx Include it to your code with $LIB "hexval.lbx" and the conversion routine from this library will be used instead of the one from mcs.lbx. The alternative library will also set the ERR flag if an illegal character is found. |
Why do you ignore the help? Somebody did use lots of efforts to write it. |
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Wed Apr 15, 2020 5:06 pm Post subject: |
|
|
MWS wrote: | Quote: | ...you can use the alternative library named hexval.lbx Include it to your code with $LIB "hexval.lbx" and the conversion routine from this library will be used instead of the one from mcs.lbx. The alternative library will also set the ERR flag if an illegal character is found. |
Why do you ignore the help? Somebody did use lots of efforts to write it. |
I did not deliberately ignore it. I simply did not find any help regarding how to use the ERR flag.
Some items do not come up in the index. |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Apr 15, 2020 5:21 pm Post subject: |
|
|
Just two questions. Have you read the help?
did you use the simulator?
JP
sorry MWS answers your request before me, but it is in the same way _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Apr 15, 2020 5:33 pm Post subject: |
|
|
rkumetz wrote: | I simply did not find any help regarding how to use the ERR flag. |
My quote was from the explanation to HEXVAL, starting with the seventh sentence, it must have taken serious efforts to miss it. |
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Wed Apr 15, 2020 5:39 pm Post subject: |
|
|
Cynicism is a waste of energy. If that sentence was USEFUL to me then I would not have asked a question.
That would be a waste of your time and mine and I do not endeavor to do either.
I apologize. I suppose my question should have been "how do I check the ERR flag in BASCOM?"
A search on ERR, ERR FLAG and various other combinations in HELP produce host of results but all are similar to the
sentence that you pointed out.
How does one check the ERR flag from BASCOM to allow the code to react accordingly when the string contains characters
which are not valid Hex digits? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Apr 15, 2020 5:49 pm Post subject: |
|
|
ERR is a global error bit. it is used by many routines.
you simply test it after using hexval()
Code: | If ERR=1 then
print "problem"
end if |
of course then the conversion already has been done. in order to test a string in advance you would need to test the string. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Apr 15, 2020 5:53 pm Post subject: |
|
|
rkumetz wrote: | I suppose my question should have been "how do I check the ERR flag in BASCOM?" |
Now you're doing running fight, actually you didn't read about the lbx, otherwise you would have asked more specifically.
You do not have to give the impression that you not have missed it, as this may happen to anyone.
Quote: | Cynicism is a waste of energy. If that sentence was USEFUL to me then I would not have asked a question. |
What you call 'cynism' is my friendly way not to ask, whether you would find your rear in bright sunlight.
Quote: | How does one check the ERR flag from BASCOM to allow the code to react accordingly |
Immediately after conversion do a:
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Apr 15, 2020 5:55 pm Post subject: |
|
|
Hi Mark,
this is the ultimate wisdom of the day:
Quote: | in order to test a string in advance you would need to test the string. |
|
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Wed Apr 15, 2020 7:08 pm Post subject: |
|
|
albertsm wrote: | ERR is a global error bit. it is used by many routines.
you simply test it after using hexval()
Code: | If ERR=1 then
print "problem"
end if |
of course then the conversion already has been done. in order to test a string in advance you would need to test the string. |
Assuming that performing a conversion on a string which contains characters which are not valid hex merely sets the ERR flag and
produces an incorrect result it will be sufficient to know that the result of the conversion is not usable.
Can I correctly assume from the description of the lbx that it will not cause the code to do anything odd and jump into hyperspace? :D |
|
Back to top |
|
|
rkumetz
Joined: 23 Jan 2007 Posts: 165 Location: Vermont
|
Posted: Wed Apr 15, 2020 7:10 pm Post subject: |
|
|
MWS wrote: |
Immediately after conversion do a:
|
Thanks. THAT is what I was looking for! |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Apr 15, 2020 7:12 pm Post subject: |
|
|
yes what i wrote is both very wise and very stupid
maybe i am affected a bit by Cruijff. I lived in the same village and street, but not at the same time. He said :
- every advantage has its disadvantage.
- you have to shoot otherwise you can not win
- if we have the ball, they can not win
And lot more. i know nothing about football, but that made me smile.
ok, what i meant to say is that there is a difference between testing in advance, or converting and then checking if the conversion was right.
i have seen functions like isNum, isfloat, ishex, etc. and probably the idea is that you can test since otherwise an error is raised. or that the testing takes less resources.
for this case (hex), i would however use the ERR flag method. _________________ Mark |
|
Back to top |
|
|
|