How to convert integer to bytes

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
California
Posts: 361
Joined: 14 Dec 2005 20:56
Location: Slovenia

How to convert integer to bytes

#1 Post by California » 26 Mar 2023 12:14

Ok, simple question (who knows).
Example:
I have an integer value of 2565 which should be converted into hex (not hex string), result is 0x0A05.
So in code it would be like:

Code: Select all

sub procedure Conversion()   
    dim a    as integer
    dim b    as byte
    dim c    as byte

    

    a = 2565
    IntToHex(a, text)  ' correct result, but in string format
    xxx = ..... ?          
    b = hi(xxx)   ' 0x0A
    c = lo(xxx)   ' 0x05
end sub
Yor help would be very appreciatted.
Regards,
Vlado

Smart_Aleck
Posts: 16
Joined: 07 Feb 2023 20:45

Re: How to convert integer to bytes

#2 Post by Smart_Aleck » 26 Mar 2023 13:28

Hi,

isn't it, that "a" is already holding a hex value?

I think you only need to take hi() and lo() from "a".

BR
SA

Firewire
Posts: 166
Joined: 20 Jun 2009 17:12

Re: How to convert integer to bytes

#3 Post by Firewire » 26 Mar 2023 13:38

Code: Select all

sub procedure Conversion()   
    dim a    as integer
    dim b    as byte
    dim c    as byte

    

    a = 2565
    IntToHex(a, text)  ' correct result, but in string format
    xxx = ..... ?          
    b = hi(a)   ' 0x0A
    c = lo(a)   ' 0x05
end sub

California
Posts: 361
Joined: 14 Dec 2005 20:56
Location: Slovenia

Re: How to convert integer to bytes

#4 Post by California » 26 Mar 2023 17:17

Well, yes it couldn't be more simple.
Thanks for your help,

Regards
Vlado

Post Reply

Return to “mikroBasic PRO for PIC General”