VB.Net 2005

G

Guest

Does anyone know if Microsoft will have support for binary operations such as:

Dim a as short
if (a and %1100110011110000) = 0, then
..........
Dennis in Houston
 
H

Herfried K. Wagner [MVP]

* =?Utf-8?B?RGVubmlz?= said:
Does anyone know if Microsoft will have support for binary operations such as:

Dim a as short
if (a and %1100110011110000) = 0, then

AFAIK no.
 
G

Guest

Sorry to hear that. Direct bitwise with the various operators is one of the few remaining weakness of VB.
 
G

Guest

I am confused here, i thought it did!

dim a as integer = 15
dim b as integer = 3
dim r as integer
r = a and b
' r now = 3 isnt thsi what you want?

puzzled

guy
 
C

Cor Ligthert

AFAIK no.
There will be some more bitwise operating I thought or better there is
already, however you knows this better to me, so I think that this
explanation is to short.

(As well for me of course, to clean maybe a misunderstanding from me)

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

No, he wants to use Binary literals in his expressions like with hex for
example, &HFF. He wants to write %11111111

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
O

One Handed Man \( OHM - Terry Burns \)

The only thing I can suggest is that you write a class for converting binary
represented string values into shorts something like.

PSEUDO!
Class ConvertMe

Public Function ToShort( ByVal str as String ) as short

Dim c as MyShort

'Get the string is valid
'Else throw an exception


For each c in str
MyShort << 1
MyShort = MyShort And ValueOf( c )
End Function


Return c


End Class

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
There will be some more bitwise operating I thought or better there is
already, however you knows this better to me, so I think that this
explanation is to short.

Sure, but there will not be binary number literals, like '&B10010101'.
 
H

Herfried K. Wagner [MVP]

* =?Utf-8?B?RGVubmlz?= said:
Sorry to hear that. Direct bitwise with the various operators is one of the few remaining weakness of VB.

I am currently discussing with some folks about this idea. Basically I
like it, but there are problems associated with it too. Consider this
code:

\\\
If (Foo And &B11101010101110101011101010010010 = &B11101010101110101011101010010010 Then
...
End If
///

A little typo and you will get a wrong result...
 
C

Cor Ligthert

Sure, but there will not be binary number literals, like '&B10010101'.
Good explanation.

I hope that we both agree that this would be crazy in a language like VBnet?

Thanks

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Good explanation.

I hope that we both agree that this would be crazy in a language like VBnet?

I would allow binary integer literals:

\\\
<Flags()> _
Public Enum Goo
None = &B0
A = &B1
B = &B10
C = &B100
D = &B1000
End Enum
///

;-)
 
J

Jay B. Harlow [MVP - Outlook]

Herfried,
I normally use:
<Flags()> _
Public Enum Goo
None = 0
A = 1 << 0
B = 1 << 1
C = 1 << 2
D = 1 << 3
End Enum

Where the 1 is shifted over the bit position.

I agree I've wanted binary constants once or twice.

Just a thought
Jay
 
J

Jeff Johnson [MVP: VB]

MyShort = MyShort And ValueOf( c )

Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].
 
C

Cor Ligthert

Hi Jeff,

To help Terry a little bit, you quoted him (probably by accident) wrong
Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].

:)

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

No it's Pseudo code.

Basically what I am trying to impart is that you could construct a number
from a string representing a binary number so in your test u could have
written.


if ( a And ToShort( "01000100100100") ) Then

' Do Stuff




--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Jeff Johnson said:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
MyShort = MyShort And ValueOf( c )

Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].
 
H

Herfried K. Wagner [MVP]

* "Jeff Johnson said:
MyShort = MyShort And ValueOf( c )

Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].

It's pseudo code, or in other words, a method that takes a string
consisting of "0" and "1" characters. 'ValueOf' would return its
integer value.

Still, performance will be bad, especially for longer strings. Natively
supporting binary number /literals/ that are converted at compile-time
would be a far better approach.

Currently, you can use this code to get the behavior of 'ValueOf':

\\\
Public Function ValueOf(ByVal BinaryString As String) As Integer
Return Convert.ToInt32(BinaryString, 2)
End Function
///
 
H

Herfried K. Wagner [MVP]

Jay,

* "Jay B. Harlow said:
I normally use:


Where the 1 is shifted over the bit position.

Full ACK. I prefer this way too.
I agree I've wanted binary constants once or twice.

I just throught in which situations binary number literals would make
sense, and the case of a little enum was one of the most useful cases I
was able to find. So, in everyday programming, binary number literals
don't make much sense, which still doesn't mean that it should not be
possible to use them ;-).
 
C

Cor Ligthert

Full ACK. I prefer this way too.


I just throught in which situations binary number literals would make
sense, and the case of a little enum was one of the most useful cases I
was able to find. So, in everyday programming, binary number literals
don't make much sense, which still doesn't mean that it should not be
possible to use them ;-).

Again why? Because sometimes to much is no benefit, it can make simple
things suddenly more difficult. Example OR and ELSE.

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

Yes, I agree completely, however, in the absence of those binary literals,
if the OP wanted to be able to write out a string of ones and zeros in the
programming then this is one option available now.

Given that Visual Basic, has little support for accessing the pc's IO, its
probably not much of a requirement.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Herfried K. Wagner said:
* "Jeff Johnson said:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
MyShort = MyShort And ValueOf( c )

Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].

It's pseudo code, or in other words, a method that takes a string
consisting of "0" and "1" characters. 'ValueOf' would return its
integer value.

Still, performance will be bad, especially for longer strings. Natively
supporting binary number /literals/ that are converted at compile-time
would be a far better approach.

Currently, you can use this code to get the behavior of 'ValueOf':

\\\
Public Function ValueOf(ByVal BinaryString As String) As Integer
Return Convert.ToInt32(BinaryString, 2)
End Function
///
 
O

One Handed Man \( OHM - Terry Burns \)

Actually, it's one of those things you almost never want to do, so I was
suprised that this overloaded ToInt32 had no less than ( 19 ) overloads and
one of them did the trick, well spotted H.

Regards - OHM

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

One Handed Man ( OHM - Terry Burns ) said:
Yes, I agree completely, however, in the absence of those binary literals,
if the OP wanted to be able to write out a string of ones and zeros in the
programming then this is one option available now.

Given that Visual Basic, has little support for accessing the pc's IO, its
probably not much of a requirement.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Herfried K. Wagner said:
* "Jeff Johnson said:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message

MyShort = MyShort And ValueOf( c )

Is ValueOf() somthing you wrote yourself? I looked in MSDN and the only
place I could find this was under JScript[.NET].

It's pseudo code, or in other words, a method that takes a string
consisting of "0" and "1" characters. 'ValueOf' would return its
integer value.

Still, performance will be bad, especially for longer strings. Natively
supporting binary number /literals/ that are converted at compile-time
would be a far better approach.

Currently, you can use this code to get the behavior of 'ValueOf':

\\\
Public Function ValueOf(ByVal BinaryString As String) As Integer
Return Convert.ToInt32(BinaryString, 2)
End Function
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top