Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

HEXVAL

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Wed Apr 15, 2020 3:33 pm    Post subject: HEXVAL Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Wed Apr 15, 2020 5:01 pm    Post subject: Reply with quote

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
View user's profile
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Wed Apr 15, 2020 5:06 pm    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Wed Apr 15, 2020 5:21 pm    Post subject: Reply with quote

Just two questions. Have you read the help?
did you use the simulator?

JP Wink
sorry MWS answers your request before me, but it is in the same way

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Wed Apr 15, 2020 5:33 pm    Post subject: Reply with quote

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
View user's profile
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Wed Apr 15, 2020 5:39 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5003
Location: Holland

blank.gif
PostPosted: Wed Apr 15, 2020 5:49 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Wed Apr 15, 2020 5:53 pm    Post subject: Reply with quote

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. Very Happy
Quote:
How does one check the ERR flag from BASCOM to allow the code to react accordingly

Immediately after conversion do a:
Code:
If Err = 1 Then
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1803

blank.gif
PostPosted: Wed Apr 15, 2020 5:55 pm    Post subject: Reply with quote

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.

Smile
Back to top
View user's profile
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Wed Apr 15, 2020 7:08 pm    Post subject: Reply with quote

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
View user's profile
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Wed Apr 15, 2020 7:10 pm    Post subject: Reply with quote

MWS wrote:

Immediately after conversion do a:
Code:
If Err = 1 Then


Thanks. THAT is what I was looking for!
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5003
Location: Holland

blank.gif
PostPosted: Wed Apr 15, 2020 7:12 pm    Post subject: Reply with quote

yes what i wrote is both very wise and very stupid Very Happy

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum