Results 1 to 7 of 7

Thread: 2's Compliment - [RESOLVED]

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    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

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    VB Code:
    1. msgbox hex(-12345)

    Or did I mis-understand the question???
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    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

  4. #4
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Well, yes this IS VB, the other way around is DEC(hexnum)
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Hex colors to long RGB colors?

    VB Code:
    1. Public Function HEXCOL2RGB(ByVal HexColor As String) As Long
    2.  
    3.  
    4. Dim Red As String
    5. Dim Green As String
    6. Dim Blue As String
    7.  
    8. HexColor = Replace(HexColor, "#", "")
    9.     'Here HexColor = "00FF1F"
    10.  
    11. Red = Val("&H" & Mid(HexColor, 1, 2))
    12.     'The red value is now the long version of "00"
    13.  
    14. Green = Val("&H" & Mid(HexColor, 3, 2))
    15.     'The red value is now the long version of "FF"
    16.  
    17. Blue = Val("&H" & Mid(HexColor, 5, 2))
    18.     'The red value is now the long version of "1F"
    19.  
    20.  
    21. HEXCOL2RGB = RGB(Red, Green, Blue)
    22.     'The output is an RGB value
    23.  
    24. End Function

    NOTE: The return value of that function is a LONG value.

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147
    Dont worry i have sorted it. I had a moment of insparation:

    VB Code:
    1. Dim Sample As Long
    2. Dim Answer As Long
    3.  
    4. Sample = (MSW*65536)+LSW
    5.  
    6. If Sample>32768 Then
    7.    Answer = ((65536-Sample)+1)*-1)
    8. Else
    9.   Answer = Sample
    10. End If
    Mik706

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    *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
  •  



Click Here to Expand Forum to Full Width