VB.Net 2005

H

Herfried K. Wagner [MVP]

* Cor Ligthert said:
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...
 
J

Jeff Johnson [MVP: VB]

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....
 
J

Jay B. Harlow [MVP - Outlook]

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
 
O

One Handed Man \( OHM - Terry Burns \)

LOL

--

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

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

One Handed Man \( OHM - Terry Burns \)

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
 
H

Herfried K. Wagner [MVP]

* "Jay B. Harlow said:
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 ;-).
 
D

Dennis D.

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

Dennis D.

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. said:
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 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