|
-
Mar 2nd, 2004, 03:33 AM
#1
Thread Starter
Addicted Member
2's Compliment - [RESOLVED]
I have the following problem which i know should be straight forward but i just cannot see the solution:
i have two 16bit words which i need to combine to get a 32bit signed long.
ie -123456 is stored as FFFE hex (MSW) and 1DC0 hex (LSW).
how do i get from the Hex values to the long value? (Code please)
Last edited by mik706; Mar 2nd, 2004 at 04:26 AM.
Mik706
-
Mar 2nd, 2004, 04:15 AM
#2
Or did I mis-understand the question???
-
Mar 2nd, 2004, 04:18 AM
#3
Somehow I don't think is Visual Basic.
I think in the C++ headers there is some code to convert from Hex to Long, and vice versa. Is this VB?
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Mar 2nd, 2004, 04:20 AM
#4
Well, yes this IS VB, the other way around is DEC(hexnum)
-
Mar 2nd, 2004, 04:22 AM
#5
Hex colors to long RGB colors?
VB Code:
Public Function HEXCOL2RGB(ByVal HexColor As String) As Long
Dim Red As String
Dim Green As String
Dim Blue As String
HexColor = Replace(HexColor, "#", "")
'Here HexColor = "00FF1F"
Red = Val("&H" & Mid(HexColor, 1, 2))
'The red value is now the long version of "00"
Green = Val("&H" & Mid(HexColor, 3, 2))
'The red value is now the long version of "FF"
Blue = Val("&H" & Mid(HexColor, 5, 2))
'The red value is now the long version of "1F"
HEXCOL2RGB = RGB(Red, Green, Blue)
'The output is an RGB value
End Function
NOTE: The return value of that function is a LONG value.
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Mar 2nd, 2004, 04:26 AM
#6
Thread Starter
Addicted Member
Dont worry i have sorted it. I had a moment of insparation:
VB Code:
Dim Sample As Long
Dim Answer As Long
Sample = (MSW*65536)+LSW
If Sample>32768 Then
Answer = ((65536-Sample)+1)*-1)
Else
Answer = Sample
End If
-
Mar 2nd, 2004, 04:28 AM
#7
*looks at his backup*
Ah, I had that in my backups. Not exactly the same though 
Didn't quite understand what you wanted..
Nice..
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|