diff options
author | Wei Wang <weiwa@google.com> | 2014-10-29 15:29:32 -0700 |
---|---|---|
committer | Wei Wang <weiwa@google.com> | 2014-10-29 15:40:36 -0700 |
commit | ac67c808d9c8072da9f36c1a964ee78135f42edb (patch) | |
tree | cfde75674053947d4c9d2fd77e693e7913fedbbf /src/com/android/bluetooth/util | |
parent | e60b413fa9920c2210cf4a31c8b660593b4d4415 (diff) | |
download | android_packages_apps_Bluetooth-ac67c808d9c8072da9f36c1a964ee78135f42edb.tar.gz android_packages_apps_Bluetooth-ac67c808d9c8072da9f36c1a964ee78135f42edb.tar.bz2 android_packages_apps_Bluetooth-ac67c808d9c8072da9f36c1a964ee78135f42edb.zip |
Fix batch timestamp parsing error.
Bug:18166784
Change-Id: I4817a1410c570bd1fa59425c257fb4a3d96e9e1f
Diffstat (limited to 'src/com/android/bluetooth/util')
-rw-r--r-- | src/com/android/bluetooth/util/NumberUtils.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/com/android/bluetooth/util/NumberUtils.java b/src/com/android/bluetooth/util/NumberUtils.java new file mode 100644 index 000000000..1d2745660 --- /dev/null +++ b/src/com/android/bluetooth/util/NumberUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.bluetooth.util; + +/** + * Utility for parsing numbers in Bluetooth. + */ +public class NumberUtils { + + /** + * Convert a byte to unsigned int. + */ + public static int unsignedByteToInt(byte b) { + return b & 0xFF; + } + + /** + * Convert a little endian byte array to integer. + */ + public static int littleEndianByteArrayToInt(byte[] bytes) { + int length = bytes.length; + if (length == 0) { + return 0; + } + int result = 0; + for (int i = length - 1; i >= 0; i--) { + int value = unsignedByteToInt(bytes[i]); + result += (value << (i * 8)); + } + return result; + } +} |