johnadonaldson
Well-known member
- Joined
- Nov 9, 2005
- Messages
- 48
- Programming Experience
- 10+
I am attempting to write a function to Shift Right bits.
Private Function ShiftR(ByVal Number As Long, ByVal Shift As Integer)
Dim nIndex As Integer
For nIndex = 1 To Shift
Number = Number / 2
Next
Return Number
End Function
The problem is is it works up to a point. Consider this:
Number = F8
F8 -> 7C Shift = 1 Correct
7C -> 3E Shift = 2 Correct
3E -> 1F Shift = 3 Correct
1F -> 10 Shift = 4 - Error should be 0F.
Is there a better way..... Is there a built in function like in C.
Private Function ShiftR(ByVal Number As Long, ByVal Shift As Integer)
Dim nIndex As Integer
For nIndex = 1 To Shift
Number = Number / 2
Next
Return Number
End Function
The problem is is it works up to a point. Consider this:
Number = F8
F8 -> 7C Shift = 1 Correct
7C -> 3E Shift = 2 Correct
3E -> 1F Shift = 3 Correct
1F -> 10 Shift = 4 - Error should be 0F.
Is there a better way..... Is there a built in function like in C.