By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

VB.Net 2005

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
28 Replies


P: n/a
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
Sorry to hear that. Direct bitwise with the various operators is one of the few remaining weakness of VB.
--
Dennis in Houston
"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3

P: n/a
guy
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

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4

P: n/a
> >
Dim a as short
if (a and %1100110011110000) = 0, then


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
Nov 20 '05 #5

P: n/a
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

"guy" <gu*@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
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

"Herfried K. Wagner [MVP]" wrote:
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #6

P: n/a
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

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com...
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

Nov 20 '05 #7

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Dim a as short
if (a and %1100110011110000) = 0, then


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.


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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

P: n/a
* =?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> scripsit:
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...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9

P: n/a
>
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
Nov 20 '05 #10

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
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?


I would allow binary integer literals:

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

;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl... * "Cor Ligthert" <no**********@planet.nl> scripsit:
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?
I would allow binary integer literals:

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

;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #12

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:Ou*************@TK2MSFTNGP09.phx.gbl...
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].
Nov 20 '05 #13

P: n/a
Hi Jeff,

To help Terry a little bit, you quoted him (probably by accident) wrong
PSEUDO!
bla bla bla
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].


:-)

Cor
Nov 20 '05 #14

P: n/a
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 [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Ou*************@TK2MSFTNGP09.phx.gbl...
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].

Nov 20 '05 #15

P: n/a
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:Ou*************@TK2MSFTNGP09.phx.gbl...
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #16

P: n/a
Jay,

* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
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.


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 ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #17

P: n/a
>
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 ;-).


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

Cor
Nov 20 '05 #18

P: n/a
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 [MVP]" <hi***************@gmx.at> wrote in message
news:el*************@TK2MSFTNGP09.phx.gbl...
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Ou*************@TK2MSFTNGP09.phx.gbl...
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #19

P: n/a
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 )" <news.microsoft.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
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 [MVP]" <hi***************@gmx.at> wrote in message
news:el*************@TK2MSFTNGP09.phx.gbl...
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Ou*************@TK2MSFTNGP09.phx.gbl...

> 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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #20

P: n/a
* Cor Ligthert <no**********@planet.nl> scripsit:
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 ;-).


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


I am not against binary integer number literals...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #21

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
No it's Pseudo code.


Mental block. I virtually never use pseudo code myself and the rest of the
stuff you looked so "real" it didn't occur to me, regardless of the large
PSUEDO! in your post....
Nov 20 '05 #22

P: n/a
Herfried,
I just throught in which situations binary number literals would make
I like the term "binary number literals" better then my "binary
constants"...

Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uT**************@tk2msftngp13.phx.gbl... Jay,

* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
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.


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 ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #23

P: n/a
LOL

--

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

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

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
No it's Pseudo code.


Mental block. I virtually never use pseudo code myself and the rest of the
stuff you looked so "real" it didn't occur to me, regardless of the large
PSUEDO! in your post....

Nov 20 '05 #24

P: n/a
I quickly knocked up this implementation. However, as H pointed out,
Convert.ToShort("000000000000100",2) Does the same thing and I tested the
performance, its four times quicker than my code as you might expect. But
here it is for interest sake.

Public Function ToShort(ByVal str As String) As Short

Dim x As Int16
Dim i As Int16

For i = 0 To 14

If Char.GetNumericValue(str, i) = 1 Then
x = x Or &H1
End If

x = x << 1

Next
Return x

End Function

--

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

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

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
No it's Pseudo code.


Mental block. I virtually never use pseudo code myself and the rest of the
stuff you looked so "real" it didn't occur to me, regardless of the large
PSUEDO! in your post....

Nov 20 '05 #25

P: n/a
* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
I just throught in which situations binary number literals would make


I like the term "binary number literals" better then my "binary
constants"...


Well, I didn't know the right term to use and then I took a look in the
documentation to use an appropriate term ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #26

P: n/a
I believe one of the rules of higher level languages is that the higher
level language 'must' accomodate all objects found in the lower level
languages (here: assembly). Keep in mind this code is used primarily by
machines, not by humans.

The Machine Imperatives
http://www.dennisys.com/
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:el*************@TK2MSFTNGP09.phx.gbl...
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Ou*************@TK2MSFTNGP09.phx.gbl...
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #27

P: n/a
Oops: Here's a URL on Imperative Programming:
http://www.wordiq.com/definition/Imperative_programming
"DND" Do not dismiss as unimportant; ever. - me

"Dennis D." <te**@dennisys.com> wrote in message
news:ef*************@TK2MSFTNGP09.phx.gbl...
I believe one of the rules of higher level languages is that the higher
level language 'must' accomodate all objects found in the lower level
languages (here: assembly). Keep in mind this code is used primarily by
machines, not by humans.

The Machine Imperatives
http://www.dennisys.com/
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:el*************@TK2MSFTNGP09.phx.gbl...
* "Jeff Johnson [MVP: VB]" <i.***@enough.spam> scripsit:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:Ou*************@TK2MSFTNGP09.phx.gbl...

> 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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 21 '05 #28

P: n/a
Excuse me for interupting:
Time flies when you don't know what you're doing
That is a great saying!
Where do you get your tag lines?

Dennis D.
http://www.dennisys.com/
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
LOL

--

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

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

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in

message
news:%2****************@TK2MSFTNGP09.phx.gbl...
No it's Pseudo code.


Mental block. I virtually never use pseudo code myself and the rest of the stuff you looked so "real" it didn't occur to me, regardless of the large PSUEDO! in your post....


Nov 21 '05 #29

This discussion thread is closed

Replies have been disabled for this discussion.