Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string decodePID(byte high, byte low)
- {
- // high and low are the two bytes of the code from OBD port
- /*
- Define an array of bitmasks to pull out code letter and numbers
- 11000000,
- 00110000,
- 00001111,
- 11110000,
- 00001111
- * */
- byte[] mask = new byte[] { 0xC0, 0x30, 0x0F, 0xF0, 0x0F };
- // Lookup array for binary -> PID letter conversion.
- char[] type = new char[] { 'P', 'C', 'B', 'U' };
- // define placeholder for decoded values
- char[] retStr = new char[5];
- // Look up code type by top two bits
- retStr[0] = type[(high & mask[0]) >> 6];
- // convert remaining digits
- retStr[1] = (char)(((high & mask[1]) >> 4) + 48);
- retStr[2] = (char)((high & mask[2]) + 48);
- retStr[3] = (char)(((low & mask[3]) >> 4) + 48);
- retStr[4] = (char)((low & mask[4]) + 48);
- // build string and return
- return new string(retStr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement