hex in string

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
kingGrey
Posts: 158
Joined: 08 Mar 2007 00:40
Location: portland, OR

hex in string

#1 Post by kingGrey » 27 Aug 2009 00:34

if I have a string and fill it with hex numbers, how could I get each decimal value

Code: Select all

Dim tmp as String[2]
      tmp[0] = 0xAA
      tmp[1] = 0x53
by this I mean how do I calculate this string's decimal value.?
Any ideas
Thank You for your help
An expert is a man who has made all the mistakes which can be made, in a narrow field.
http://www.stevenswater.com/catalog/stevensProductdl3000.aspx?SKU=%2793750%27

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#2 Post by anikolic » 27 Aug 2009 12:51

Hi,
The value inside a string is binary, and instead of writing tmp[0] = 0xAA, you could also write tmp[0] = 170. Can you be a little more specific what are you going to do with this read value? It wasn't clear what is your intention with this. Are you trying to make another string which contains character representation of the value in this tmp string? For example, if the value of tmp[0] is 0xAA, do you want to read it and make a

Code: Select all

dim DecimalValue as string[4]
DecimalValue = "170"
Please elaborate your problem, so I could understand and help you.

Thanks,
Aleksandar
Web Department Manager

kingGrey
Posts: 158
Joined: 08 Mar 2007 00:40
Location: portland, OR

#3 Post by kingGrey » 27 Aug 2009 16:21

well what I am actually trying to do is to be able to get the decimal representation of the hex AA53 when its stored in string tmp like

Code: Select all

Dim tmp as string[4]
tmp[0] = 0xAA
tmp[1] = 0x53
I know that the total decimal sum is 43603 but how can I convert the hex data in tmp to give me the result 43603 using a library function or some method?

getting the value is what I am interested in getting!
Thank You for your help
An expert is a man who has made all the mistakes which can be made, in a narrow field.
http://www.stevenswater.com/catalog/stevensProductdl3000.aspx?SKU=%2793750%27

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#4 Post by p.erasmus » 28 Aug 2009 09:42

I think the StrToWord(,) function should solve your problem

Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#5 Post by anikolic » 31 Aug 2009 14:54

Hi,
Currently, there is no such function as StrToWord supported by our compilers, but you can do this very easily using a few lines of code:

Code: Select all

  Dim tmp as String[2]
  dim HiLow as integer

  tmp[0] = 0xAA
  tmp[1] = 0x53

  Hi(HiLow) = tmp[0]
  Lo(HiLow) = tmp[1]
Best regards,
Aleksandar
Web Department Manager

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#6 Post by p.erasmus » 31 Aug 2009 15:58

Yes this is correct however the additional Library from yo2Lio wrtten for your compilers has these Functions .
it is downloadable from this Forum
[/quote]
Currently, there is no such function as StrToWord supported by our compilers[quote][/quote]
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

kingGrey
Posts: 158
Joined: 08 Mar 2007 00:40
Location: portland, OR

#7 Post by kingGrey » 01 Sep 2009 18:26

A better solution that I have been able to get to work is

Code: Select all

Dim myTmp as String[4]
Dim myWord as word

       tmp[0] = 0xAA
       tmp[1] = 0x53 

       myWord = tmp[0]
       wordToHex(myWord,var1)
       myWord = tmp[1]
       wordToHex(myWord,var2)

           
- perform a parse routine on var1 &2 to remove the leading zeros
- strcat var1 & 2
- and then use HexToDec converter.
Thank You for your help
An expert is a man who has made all the mistakes which can be made, in a narrow field.
http://www.stevenswater.com/catalog/stevensProductdl3000.aspx?SKU=%2793750%27

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”