473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Sign extend 16-bit value to Integer

What is the best way to sign extend a 16-bit value (such as half of
the lparam value in WM_NCxxx messages) into an Integer?

Currently I test for the 8000 bit and if set OR in FFFF0000, but it
seems like there should be some built-in way to do this.
Oct 5 '08 #1
4 4060
If it's a Short (Int16) it will widen correctly to Integer (Int32).

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:st********************************@4ax.com...
What is the best way to sign extend a 16-bit value (such as half of
the lparam value in WM_NCxxx messages) into an Integer?

Currently I test for the 8000 bit and if set OR in FFFF0000, but it
seems like there should be some built-in way to do this.
Oct 5 '08 #2
Try the following example for BitConverter to see if this works for you.

Sub Main()
Dim x32 As Int32 = &H432312AF
Dim a16, b16 As Int16 ' if you want 2 byte ints
Dim a32, b32 As Int32 ' if you want 4 byte ints
Dim ba As Byte() = BitConverter.GetBytes(x32)

a16 = BitConverter.ToInt16(ba, 0)
b16 = BitConverter.ToInt16(ba, 2)

a32 = a16 : b32 = b16

Console.Out.WriteLine(String.Format("{0:x} {1:x} {2:x}", x32, a32, b32))
Console.In.ReadLine()

End Sub

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:st********************************@4ax.com...
What is the best way to sign extend a 16-bit value (such as half of
the lparam value in WM_NCxxx messages) into an Integer?

Currently I test for the 8000 bit and if set OR in FFFF0000, but it
seems like there should be some built-in way to do this.
Oct 5 '08 #3
Thanks, that works fine.

On Sun, 5 Oct 2008 16:53:34 -0400, "Family Tree Mike"
<Fa************@ThisOldHouse.comwrote:
>Try the following example for BitConverter to see if this works for you.

Sub Main()
Dim x32 As Int32 = &H432312AF
Dim a16, b16 As Int16 ' if you want 2 byte ints
Dim a32, b32 As Int32 ' if you want 4 byte ints
Dim ba As Byte() = BitConverter.GetBytes(x32)

a16 = BitConverter.ToInt16(ba, 0)
b16 = BitConverter.ToInt16(ba, 2)

a32 = a16 : b32 = b16

Console.Out.WriteLine(String.Format("{0:x} {1:x} {2:x}", x32, a32, b32))
Console.In.ReadLine()

End Sub

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:st********************************@4ax.com.. .
>What is the best way to sign extend a 16-bit value (such as half of
the lparam value in WM_NCxxx messages) into an Integer?

Currently I test for the 8000 bit and if set OR in FFFF0000, but it
seems like there should be some built-in way to do this.
Oct 5 '08 #4
Jack,

Copied from a message in this newsgroup from Tom Spink

\\\
Dim strText = "The String Being Measured"
Dim g As Graphics = Me.CreateGraphics
Dim sfSize As SizeF = g.MeasureString(strText, Me.Font)

MsgBox("Width: " & sfSize.Width & vbCrLf & "Height: " & sfSize.Height)
///

Cor

"Jack Jackson" <jj******@cinnovations.netschreef in bericht
news:st********************************@4ax.com...
What is the best way to sign extend a 16-bit value (such as half of
the lparam value in WM_NCxxx messages) into an Integer?

Currently I test for the 8000 bit and if set OR in FFFF0000, but it
seems like there should be some built-in way to do this.

Oct 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Zierhofer | last post by:
hi there, it seems as if i can´t convert the euro and pound sign to their html equivalents. i tried eregi_replace("€", "&euro;", $haystack); eregi_replace("£", "&pound;", $haystack); as...
2
by: Boobie | last post by:
I switched to using this function to create element: ---------------------------------------------------- function elem(name, attrs, style, text) { var e = document.createElement(name); if...
5
by: Waldy | last post by:
Hi there, I am using the .Net XML Serialization classes to create XML strings. This has been working fine up until the point that one of the strings contained a pound sterling symbol. The...
4
by: Peter Tragardh | last post by:
I'm searching for info on how to authenticate a user in the same way that for example Source Safe does. I would like my system to use Windows as the authenticator, so that the user doesn't have to...
11
by: MLH | last post by:
If MsgBox(sMyCaption & " is already open@" _ & "Do you want to open a second instance of this database?@", _ vbYesNo Or vbQuestion Or vbDefaultButton2) = vbYes Then Exit Function What's the...
3
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: ...
0
by: neroliang | last post by:
PyLucene Homepage: pylucene.osafoundation.org 1.Quotas from PyLucene: """ Technically, the PyLucene programmer is not providing an 'extension' but a Python implementation of a set of methods...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
2
by: GaryDean | last post by:
This post is a "sanity check".... I have located the docs on how to sign a x.509 certificate http://msdn.microsoft.com/en-us/library/aa529277.aspx...
5
by: souporpower | last post by:
Hi All I am using ajax as follows: var parameters = "groups=" + escape(myemail+100@gmail.com); var url="/mydomain/ajaxCall"; if (req != null) { req.open("POST", url, true);
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.