Bitwise Operations, Combining 3 Bytes To Long

Dec 4, 2011

I am trying to combine three Byte values to one Long value, like System.Drawing.Color.ToArgb() does.

I've looked up reference source code to find it and converted it to VB .NET:

Return CLng((CInt(red) << 16 Or CInt(green) << 8 Or blue Or CInt(alpha) << 24) And -1)

It works fine of course, but I don't really understand why alpha shifted by 24 is last, not first (so it would be in nice order 24, 16, 8). I don't really understand bitwise operations a lot. Also, this code snippet works for 4 bytes, which is redundant for me, I need just three bytes and I wonder if Long is still required when bytes are only three, wouldn't Integer do just fine in this case?

So, my question is, how do I rewrite this code to work with just 3 parameters? Do I need to use Long? And, I know this is silly, but is it possible to make byte shifting in order 16,8,0 instead of 16,8,0,24? It's really just aesthetics, but I am awful perfectionist.

View 3 Replies


ADVERTISEMENT

C# - Bitwise Operations In Visual Basic .NET?

Jul 19, 2010

I'm re-writing some old application in VB.NET to C# and ASP.NET 3.5. Everything is going OK but I have this problem - and, as the database will not be changed, I must find a solution to it.The old app saves the list o desired days (from Sunday to Saturday) in a byte. This is the way it do it:

If chkDaily.Checked Then
daysBitmask = 127 ' This is for a full week
Else

[code]....

View 1 Replies

Streamreader Limits - The Streamreader Works Fine Until The File Is More Than 100,000 Bytes Long?

Apr 19, 2011

I have a problem with a streamreader in visual basic 2008.I am updating a database from text files on an ftp server. The streamreader works fine until the file is more than 100,000 bytes long.It reads until it reaches this point and then just ends. No error message, it just reads to this point which happens to be 2 fields out of 6 in the database stream. My question is - does the streamreader have a limit? And if so what is a workaround?

Dim connString As String = "Data Source=" & pDataBase
conn = New SqlCeConnection(connString)
Dim strQuery As String = ""[code]......

View 4 Replies

RijnDael Encryption/decryption - Select The Key Bytes And The Block Bytes From The Numeric Up/down?

Nov 13, 2010

I want it to do is that you input a string, then you select an algorithm (Theres only going to be one RijnDael) then you input a key, then the Initialization Vector comes from "txtIV.text" then you select the key bytes and the block bytes from the numeric up/down, then you either encrypt or decrypt.

View 1 Replies

Generic Restriction - Dont Select The Key Bytes And The Block Bytes From The Numeric Up/down?

Sep 16, 2011

Ok i am having some issues designing a base-class to handle generics.Caveat is i need to restrict the type put in as a Numeric type, specifically Int16, Int32, or Int64 (Short or Long).I know you can do Of T as {Structure} but i dont want to select the key bytes and the block bytes from the numeric up/down.

View 2 Replies

Bytes Written Exceed The Content-Length Bytes In XML Post?

Feb 19, 2011

I keep getting a ProtocolViolationException "Bytes to be written to the stream exceed the Content-Length bytes size specified." on the following code.I've tried setting Content-Length numerous ways with no success.

Dim url = "https://domain.com"
Dim req As WebRequest = WebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/xml"

[Code]...

View 1 Replies

VS 2008 What Does This Line Exactly Do - I = Stream.Read(bytes, 0, Bytes.Length)

Dec 28, 2010

What exactly does this line do?

i = stream.Read(bytes, 0, bytes.Length)

Does it read the entire message string sent by the client? I have a line to write to the stream later in the code and that does not seem to be sending anything back to the client, although the code around is excuting.

i = stream.Read(bytes, 0, bytes.Length)
While (i <> 0)
Try
' Translate data bytes to a ASCII string.

[code].....

View 3 Replies

VS 2008 Way Of Coding In Stead Of Writting Long Long Paragraphs

Sep 18, 2011

Is there a easer way of coding in stead of wrighting long long paragraphs like this in one line [code]All of this is on one line and i got lots of info to put down.."The game will begin on your 16th birthday with your mother waking you up. Today you are to go to the castle for the first time. Leave your bed and open your dresser for a Strength Seed. "

View 2 Replies

Read 2 Bytes Out Of 4 Bytes From A Text File?

Sep 22, 2011

I created a text file contains 4 bytes of data

AABBCCDD

I just want to read the first 2 bytes (AABB) to execute it with my program.

Then I'll need to read the last 2 bytes (CCDD) for another computer routines

View 3 Replies

Bitwise Comparison

Dec 30, 2010

result = SendMessage(buttonhandle, BM_GETSTATE, 0, 0)
buttonChecked = (result = BST_CHECKED)

Now I want to know whether the bit for BST_CHECKED is turned on or not.

How would I do that?

I can do

buttonChecked = (result % 2 = BST_CHECKED)

Is there a better way?

View 2 Replies

Converting Bitwise And/not From C#?

Jul 21, 2011

Original Code (VB.net): curStyle = curStyle And (Not ES_NUMBER)

Changed Code (C#):
curStyle = curStyle & (!ES_NUMBER);

But it is giving me this error: Operator '!' cannot be applied to operand of type 'long'ES_NUMBER is of data type long.I tried changing it to int, string, etc. All doesn't work.

View 4 Replies

Bitwise Shift - Getting Different Results In C#.net Vs PHP

May 15, 2011

When I run this command in PHP, I get:

[Code]...

The interesting thing is, that when I try to shift any number greater than int32 in .net, it yields bad results.. Every number under int32 (2147483647) yields the same results from php and c#.net or vb.net Is there a workaround for this in .net?

View 2 Replies

Bitwise-Logical-Operators?

Dec 29, 2010

Did anyone else read this article under Visual Basic News? I thought it was a very bad treatment of the subject. I especially don't like articles like that when the code they post relies on Option Strict Off.

View 12 Replies

Boolean - Bitwise-AND Operation In .NET?

Oct 28, 2010

I want to perform a bitwise-AND operation in VB.NET, taking a Short (16-bit) variable and ANDing it with '0000000011111111' (thereby retaining only the least-significant byte / 8 least-significant bits).

View 3 Replies

Logical And Bitwise Operators?

Aug 9, 2011

According to MSDN The And operator can act as a bitwise operator OR a logical operator.The only way to know if it is used as One operator or another is, If it is on the right side of an assignment operation? for example x = 3 AND 5. I cannot find any other instances where the bitwise operator would be used instead of the logical operator, are there?

View 1 Replies

Operators - How To Bitwise Shift In .NET

Sep 13, 2009

How do I bitwise shift right/left in VB.NET? Does it even have operators for this, or do I have to use some utility method?

View 4 Replies

Display KB Not Bytes 391 KB (401303 Bytes)

Aug 2, 2009

Probably missing something silly here, Her eis what my display looks like Sending image...(401303) I would prefer it displays as Sending image...(391 kb)

[Code]...

View 7 Replies

Bitwise Property Values In Designer?

Aug 24, 2009

I have an abstract user control(baseModule) that has a property that I plan on using a bitwise comparison on to determine what export types are supported by that module. In the designer of a module derived from baseModule, I am presented with a combobox with the ability to just select a single value (Html, Xml, etc.) I would like to be presented with a drop-down checked listbox so I could select which values I want.How can I accomplish this inside of VS2008? I've seen other properties support this.

Public Class ExportTypes
Public Enum ExportType
Html = 1
Xml = 2[code]......

View 1 Replies

Changing File Attributes (BitWise)?

Jun 14, 2009

m_ArchiveBoolean, m_HiddenBoolean, m_ReadOnlyBoolean, m_IndexedBoolean, m_CompressedBoolean are all form level booleans that's set from their appropriate Checkboxes on the form before this code runs in a BackgroundWorker.

Why is it that this code works:

Try
Dim fi As New FileInfo(element)
With fi
If m_ArchiveBoolean = False Then

[code]....

In this 2nd one attributes are being changed, but they're the wrong ones and I can't pinpoint it right off hand.

Edit: What the overall goal of this is that if the user has the attribute checkbox checked then the file needs to have it set, other wise the attribute (if it's present) needs to be unset.

View 7 Replies

Private Declare Function BlockInput Lib "user32" (ByVal FBlock As Long) As Long?

Dec 26, 2009

In Visual Studio 2008 I am using :Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long To stop input from occuring during a search-replace operation.

BlockInput(True) ' do not allow input during search and destroy
Dim cursorIcon As Cursor
cursorIcon = Cursor
Cursor.Current = Cursors.WaitCursor

Then setting it to false at the end of the operation. It did not work, so I thought maybe it was because I was calling it from a child window, so I created a function in the mainwindow, and ran it like this:

FrmMain.BlockFrmMainInput()With these functions is the Main window:

[Code]...

It did not solve the problem. I thought maybe it was because I was running under the debugger, so I tried compiling and running it debugger-free, but that did not do any better. I am still getting input when I double-click the mouse on either form.

View 2 Replies

Set A Large Constant With Bitwise Operation On ULong?

Mar 1, 2010

This work nicely

Public Const test As ULong = 1 << 30
This doesn't work nicely
Public Const test As ULong = 1 << 31

[code].....

View 2 Replies

VS 2008 Bitwise Operation (Reversing Bits)?

Feb 16, 2011

I have written a simple VB.net application which saves information to an RFID tag. I am now trying to compress my data. The solution I have come up with involves bitwire operation.Basically I store 2 numbers per 1 byte (0-9, 10 being a period, 12 possibly being a negative/positive flag,13,14,15 unused as of yet).The code I am using basically shifts the byte containing a number left, 4 spaces, then 'OR's it against another number.Therefore 12 is now represented as 00010010. The problem i'm having is decompressing. Obviously getting the '1' back is easy, as I just shift right 4, then grab it. I need to append or remove the last 4 bits.My solution after many headaches was to reverse the bit order, shift left 4, then reverse, then tostring it.

View 17 Replies

VS 2008 Changing File Attributes (BitWise)?

Jul 3, 2010

m_ArchiveBoolean, m_HiddenBoolean, m_ReadOnlyBoolean, m_IndexedBoolean, m_CompressedBoolean are all form level booleans that's set from their appropriate Checkboxes on the form before this code runs in a BackgroundWorker.

Why is it that this code works:
Try
Dim fi As New FileInfo(element)

[code].....

View 9 Replies

Combining Two Wav Files?

Aug 18, 2010

i have to combine 2 wav files in my project.

View 1 Replies

Drawbacks Of Combining C# And .NET?

Apr 28, 2012

I'm a long time VB.NET developer and has recently switched to C#. I found out that some of the built-in VB.NET functions (which predates .NET back to 6.0 and BASIC itself) such as the String.Left, or Right, or advanced functions like saving to the registry (SaveSettings and GetSettings) are noticeably absent. What I did was create a new project in the same solution with VB.NET as its language and recreate basically all the functions I need that are available in VB.NET. And then I just call that to the C# code I'm writing.Since compiling the code in .NET pretty much boils down to the same CIL, it shouldn't matter performance-wise what language I wrote the code in or whether I mix C# with VB.

View 4 Replies

Asp.net Mvc - Combining Extension Methods?

Sep 5, 2009

I'm trying to write 2 extension methods to handle Enum types.One to use the description attribute to give some better explanation to the enum options and a second method to list the enum options and their description to use in a selectlist or some kind of collection.You can read my code up to now here:

<Extension()> _
Public Function ToDescriptionString(ByVal en As System.Enum) As String
Dim type As Type = en.GetType
Dim entries() As String = en.ToString().Split(","c)

[code]....

So my problem is both extension methods don't work that well together. The methods that converts the enum options to an ienumerable can't use the extension method to get the description.

View 1 Replies

Combining 20 Overloaded Subs Into One?

Jan 31, 2012

I'm working with a third-party library interfacing to an old database system. There's a method - CallProg that calls a "stored procedure" (for lack of a better translation - any Pick users in the crowd?). However, instead of doing something like this:

Public Sub CallProg(ProgName, ParamArray ProgArgs() As String)
...
End Sub

[code].....

View 2 Replies

Combining 3 Textbox And Dropdownlist?

Nov 11, 2009

I have 3 textbox's and 1 dropdownlist and I am trying to combine all that data into one string. Here is what I tried but is not working:

Private Sub FullAddressTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FullAddressTextBox.TextChanged
FullAddressTextBox.Text = AddressTextBox.Text & " , " & CityTextBox.Text & " , " & StateDropdown.text " , " & ZipCodeTextBox.Text
End Sub

My goal is to combine these simultaneously as whoever is filling in the data or after I hit my submit button, if so it has to occur as the first event.

I think my problem has to do with .text after the statedropdown, Is it suppose to be .tostring?

View 6 Replies

Combining DataTables Using Linq

Apr 27, 2012

I've seen several posts on the subject, but none seem to answer this particular dilemma. I have two datatables that I obtained by querying two separate servers.[code]

View 7 Replies

Combining Delegate And Template?

Dec 22, 2009

Try5Times will try a function for 5 times.that function can have any number of argument and return a boolean.

If the function return false, try again.

If the function return true, stop.

How to make such function and delegate? Is there a general delegate?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved