Board index » Visual Studio » Converting value to HEX

Converting value to HEX

Visual Studio282
I have a program that saves values in the following format:

4096,4095,4044,3900,3812,........... to a text file.



I need to know how to convert the 4096 into a HEX value in this

format: 0x40 + 0x96. This format require me to seperate the Hi bits

and Lo bits.



Can anyone help me out?


-
 

Re:Converting value to HEX

You can use the Hex function to convert decimal to Hex.



To seperate hi and lo byte, there are quite a few sample code on the net. I

found the following:



Public Function HiByte(ByVal wParam As Integer)

HiByte = wParam \ &H100 And &HFF&

End Function

Public Function LoByte(ByVal wParam As Integer)

LoByte = wParam And &HFF&

End Function



See if it helps





--

Rgds,

Anand

VB.NET MVP

www.dotnetindia.com">www.dotnetindia.com





"cmdolcet69" wrote:



Quote
I have a program that saves values in the following format:

4096,4095,4044,3900,3812,........... to a text file.



I need to know how to convert the 4096 into a HEX value in this

format: 0x40 + 0x96. This format require me to seperate the Hi bits

and Lo bits.



Can anyone help me out?





-

Re:Converting value to HEX

On Sep 7, 11:50 am, Anand[MVP] <Anand...@discussions.microsoft.com>

wrote:

Quote
You can use the Hex function to convert decimal to Hex.



To seperate hi and lo byte, there are quite a few sample code on the net. I

found the following:



Public Function HiByte(ByVal wParam As Integer)

HiByte = wParam \ &H100 And &HFF&

End Function

Public Function LoByte(ByVal wParam As Integer)

LoByte = wParam And &HFF&

End Function



See if it helps



--

Rgds,

Anand

VB.NET MVPwww.dotnetindia.com">www.dotnetindia.com







"cmdolcet69" wrote:

>I have a program that saves values in the following format:

>4096,4095,4044,3900,3812,........... to a text file.



>I need to know how to convert the 4096 into a HEX value in this

>format: 0x40 + 0x96. This format require me to seperate the Hi bits

>and Lo bits.



>Can anyone help me out?- Hide quoted text -



- Show quoted text -



what is the wParam in (ByVal wParam As Integer) ?







-

Re:Converting value to HEX

cmdolcet69 wrote:

Quote
On Sep 7, 11:50 am, Anand[MVP] <Anand...@discussions.microsoft.com>

wrote:

>You can use the Hex function to convert decimal to Hex.

>

>To seperate hi and lo byte, there are quite a few sample code on the net. I

>found the following:

>

>Public Function HiByte(ByVal wParam As Integer)

>HiByte = wParam \ &H100 And &HFF&

>End Function

>Public Function LoByte(ByVal wParam As Integer)

>LoByte = wParam And &HFF&

>End Function

>



what is the wParam in (ByVal wParam As Integer) ?



That's the word value that you want to split into two bytes.





Here's another method:



Dim bytes As Byte() = BitConverter.GetBytes(3900)



bytes(0) contains low byte and bytes(1) contains high byte.



--

Göran Andersson

_____

www.guffa.com">www.guffa.com

-

Re:Converting value to HEX

On Sep 7, 12:39 pm, G=F6ran Andersson <gu...@guffa.com>wrote:

Quote
cmdolcet69 wrote:

>On Sep 7, 11:50 am, Anand[MVP] <Anand...@discussions.microsoft.com>

>wrote:

>>You can use the Hex function to convert decimal to Hex.



>>To seperate hi and lo byte, there are quite a few sample code on the n=

et. I

>>found the following:



>>Public Function HiByte(ByVal wParam As Integer)

>>HiByte =3D wParam \ &H100 And &HFF&

>>End Function

>>Public Function LoByte(ByVal wParam As Integer)

>>LoByte =3D wParam And &HFF&

>>End Function



>what is the wParam in (ByVal wParam As Integer) ?



That's the word value that you want to split into two bytes.



Here's another method:



Dim bytes As Byte() =3D BitConverter.GetBytes(3900)



bytes(0) contains low byte and bytes(1) contains high byte.



--

G=F6ran Andersson

_____www.guffa.com-">www.guffa.com- Hide quoted text -



- Show quoted text -



How do I deisplay what is inside bytes?



-

Re:Converting value to HEX

cmdolcet69 wrote:

Quote
On Sep 7, 12:39 pm, Göran Andersson <gu...@guffa.com>wrote:

>cmdolcet69 wrote:

>>On Sep 7, 11:50 am, Anand[MVP] <Anand...@discussions.microsoft.com>

>>wrote:

>>>You can use the Hex function to convert decimal to Hex.

>>>To seperate hi and lo byte, there are quite a few sample code on the net. I

>>>found the following:

>>>Public Function HiByte(ByVal wParam As Integer)

>>>HiByte = wParam \ &H100 And &HFF&

>>>End Function

>>>Public Function LoByte(ByVal wParam As Integer)

>>>LoByte = wParam And &HFF&

>>>End Function

>>what is the wParam in (ByVal wParam As Integer) ?

>That's the word value that you want to split into two bytes.

>

>Here's another method:

>

>Dim bytes As Byte() = BitConverter.GetBytes(3900)

>

>bytes(0) contains low byte and bytes(1) contains high byte.

>

>--

>Göran Andersson

>_____www.guffa.com-">www.guffa.com- Hide quoted text -

>

>- Show quoted text -



How do I deisplay what is inside bytes?





You render the value into a string and disply the string.



Example:



MyLabel.Text = bytes(0).ToString()



--

Göran Andersson

_____

www.guffa.com">www.guffa.com

-