• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

VB .NET Statement Help

Can someone please explain what this code is doing?  I've never seen the "<<" before and it looks like it's converting a true/false condition to an integer?
Dim seed As Integer = ((randomBytes(0) And &H7F) << 24 Or _
                                randomBytes(1) << 16 Or _
                                randomBytes(2) << 8 Or _
                                randomBytes(3))

Open in new window

0
nightshadz
Asked:
nightshadz
  • 3
  • 2
1 Solution
 
nightshadzAuthor Commented:
It's an extract from this code...

http://www.obviex.com/Samples/Password.aspx
0
 
Paul MacDonaldDirector, Information SystemsCommented:
Yes.  They're taking four values (randomBytes) and bitshifting them left (by 24, 16, 8 and 0 bits, respectively), and ORing them together to come up with a single, 4-byte value.
0
 
nightshadzAuthor Commented:
Thanks.  The bitshifting makes sense (have to do some more research on this to fully understand it) but I'm still not getting the Or part and how it's putting those numbers together.  Can you explain this further?
0
 
Paul MacDonaldDirector, Information SystemsCommented:
The OR operator sets a bit on if any of the ORed values is true.  So 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1.

What they're doing in the sample code is something line this

1010 0000 0000 0000
0000 1100 0000 0000
0000 0000 0010 0000
0000 0000 0000 0101
--------------------------
1010 1100 0010 0101  <- The value of the other numbers ORed together.

0
 
nightshadzAuthor Commented:
Wow, Thanks! If I could give you another million points I would!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now