Best Answer scardinale, 22 November 2015 - 06:59 PM
Can you find this method in C#?
I do not think that it is in the Micro Framework at all.
You can use the BitArray class from http://enumutils.codeplex.com/
Go to the full post  | ||||||||||||||
Best Answer scardinale, 22 November 2015 - 06:59 PM
Can you find this method in C#?
I do not think that it is in the Micro Framework at all.
You can use the BitArray class from http://enumutils.codeplex.com/ Go to the full post
6 replies to this topic
#1Posted 22 November 2015 - 04:05 PM The System.Collections.BitArray function seems to be missing in micro framework 4.3 vb. Has anyone had this problem and can it be replaced? #2Posted 22 November 2015 - 06:59 PM Best Answer Can you find this method in C#?
I do not think that it is in the Micro Framework at all.
You can use the BitArray class from http://enumutils.codeplex.com/ #3Posted 24 November 2015 - 12:36 PM The System.Collections.BitArray is in the micosoft support help pages. I just checked and it is not in C# either. I am working on a project that the hex byte returned from the device has information in the bits I need to read.
Example: bits returned in hex "00100000" the third bit is ON.
Here is the solution I came up with I know there has to be a better way but this works. To use it pass the hex value as a string and parse the returned bit string to find if it is a 1 or 0. I hope this is helps someone. I have posted in VB and C#.
Private Shared Function HexStringToBinaryString(hex As String) As String Try
Dim str As String = String.Empty
Dim c As String = String.Empty
For i = 0 To hex.Length - 1
c = hex.Substring(i, 1)
Select Case c.ToLower
Case "0"
str += "0000"
Case "1"
str += "0001"
Case "2"
str += "0010"
Case "3"
str += "0011"
Case "4"
str += "0100"
Case "5"
str += "0101"
Case "6"
str += "0110"
Case "7"
str += "0111"
Case "8"
str += "1000"
Case "9"
str += "1001"
Case "a"
str += "1010"
Case "b"
str += "1011"
Case "c"
str += "1100"
Case "d"
str += "1101"
Case "e"
str += "1110"
Case "f"
str += "1111"
End Select
Next
Return str
Catch ex As Exception
Return "00000000"
End Try
End Function
The C# version
private static string HexStringToBinaryString(string hex)
{
try {
string str = string.Empty;
string c = string.Empty;
for (i = 0; i <= hex.Length - 1; i++) {
c = hex.Substring(i, 1);
switch (c.ToLower) {
case "0":
str += "0000";
break;
case "1":
str += "0001";
break;
case "2":
str += "0010";
break;
case "3":
str += "0011";
break;
case "4":
str += "0100";
break;
case "5":
str += "0101";
break;
case "6":
str += "0110";
break;
case "7":
str += "0111";
break;
case "8":
str += "1000";
break;
case "9":
str += "1001";
break;
case "a":
str += "1010";
break;
case "b":
str += "1011";
break;
case "c":
str += "1100";
break;
case "d":
str += "1101";
break;
case "e":
str += "1110";
break;
case "f":
str += "1111";
break;
}
}
return str;
} catch (Exception ex) {
return "00000000";
}
}
#4Posted 24 November 2015 - 01:45 PM The BitArray is in the full framework and not in the Micro Framework.
How is the "Hex Byte" being returned from your device. If you are receiving a Byte array and not a string, it would be much easier and faster to check the bit with the following code: public static bool IsBitSet(byte value, byte pos) { return ((value & (((int) 1) << pos)) != 0); } #5Posted 24 November 2015 - 02:00 PM Thank you for the help. This would be much better if vb had bit shifters "<<" and ">>" they are also missing. I could use the code above with this
http://forums.netdui...ors-to-a-vbnet/
Thanks again I hope the folks at MS are reading this forum and put the bit shifters back in the vb operating system. #6Posted 24 November 2015 - 02:12 PM replace (((int) 1) << pos)) with LeftShift((int)1, pos) and you have what you need for VB. #7Posted 24 November 2015 - 02:15 PM Thanks again for the help 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||