Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > bits


Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2002, 01:30 PM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 235
Default bits


I need a tutorial on bits... I need to enter various numbers into the following bit locations but I don't know how to figure what goes where...

here is the message I send to the application:
PostMessage MMTY_HWND, MMTTY_MSG, RXM_SETVIEW, xxyy

where xxyy is the following

b0-b2 Display width of FFT spectrum
b4-b5 FFT gain
b6-b7 FFT response time
b8 XY scope size
b10-b11 XY scope quality
b12 XY scope display on/off
b13 FFT gain test mode



Also will someone explain to me this upper16 bit and lower 16 bit
again using the same format post message

PostMessage MMTY_HWND, MMTTY_MSG, RXM_WINPOS, xxyy

lParam (upper 16 bits) = Y-axis position (screen pixel value)
lParam (lower 16 bits) = X-axis position (screen pixel value)

Thanks
Rick
Reply With Quote
  #2  
Old 05-12-2002, 01:36 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

You can alter a bitmask with Or and And Not.

The bits are:
Code:
0 - 1       8 - 256
1 - 2       9 - 512
2 - 4       10 - 1024
3 - 8       11 - 2048
4 - 16      12 - 4096
5 - 32      13 - 8192
6 - 64      14 - 16384
7 - 128     15 - 32768
So if you wanted to turn bit 5 on, you would do:

Number = Number Or 32

If you wanted to turn bit 14 off, you would do:

Number = Number And (Not 16384)

__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #3  
Old 05-12-2002, 01:42 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Post

A long is a 32-bit number. That is 32 binary digits. The x and y co-ordinates only need 16 bits each, so they have been combined into one 32 bit number.
In this case the 16 bit Y is assigned to the upper 16 bits of the 32 bit long. The 16 bit X is assigned to the lower 16 bits of the 32 bit number.

In base 2 (binary) multiplying by 2 shifts the bits to one the left. That is you multiple by 2^1. To shift 2 places you multiple by 2 twice. Ie 2^2.

So to get the y co-ord in to the upper 16 bits you need to multiple by 2 ^ 16. You need add then OR in the lower 16 bits (the x co-ord).

So the code you want is:
Code:
Function Make32BitNum(ByVal iUpper As Integer, ByVal iLower As Integer) As Long
    Make32BitNum = (iUpper * 2 ^ 16) Or iLower
End Function
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #4  
Old 05-12-2002, 01:48 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
Post

Also remember that signed numbers (as all numbers in VB are) use a scheme called two's complement. Basically to get the negative version of a number you invert it and then add 1. So to invert 12 you'd have this:

12 = 00001100

invert to gives the negative in 1's complement:

-12 = 11110011

then add one to give the negative in 2's complement:

-12 = 11110100

Note that for all negative numbers the leftmost bit is zero bits is 1 and for all positive numbers the leftmost bit is 0.

To work out a negative number from the bit pattern you have to take the ordinal value of the leftmost bit, invert it and then add the ordinal values of the other bits that are 1:

11110100 = -128 + 64 + 32 + 16 + 4 = -12
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->