蓝牙UUID及其128位换算

最近一直在弄BLE设备与手机的连通,学习了uuid读取以及蓝牙UUID的换算。


摘自蓝牙核心规格文档《Core_V4.0.pdf》

A UUID is a universally unique identifier that is guaranteed to be unique across all space and all time.  UUIDs can be independently  created in a distributed fashion. No central registry of assigned UUIDs is required.  A UUID is a 128-bit value.
To reduce the burden of storing and tr ansferring 128-bit UUID values, a range of UUID values has been pre-allocated for assignment to often-used, regis-tered purposes. The first UUID in this  pre-allocated range  is known as the Bluetooth Base UUID and has the value 000000 00-0000-1000-8000-00805F9B34FB, from the Bluetooth  Assigned Numbers document. UUID val-ues in the pre-allocated range have aliases that are represented as 16-bit or 32-bit values. These aliases  are often called 16-bit and  32-bit UUIDs, but it is important to note that each actually represents a 128-bit UUID value.

The full 128-bit value of a 16-bit or 32-bit UUID may be computed by a simple arithmetic operation.

128_bit_value=16_bit_value*2^96+Bluetooth_Base_UUID 

128_bit_value=32_bit_value*2^96+BIuetooth_Base_UUID

A 16-bit UUID may be converted to 32-bit UUID format by zero-extending the 16-bit value to 32-bits. An equivalent method is to add  the 16-bit UUID value to a zero-valued 32-bit UUID.
Note that two 16-bit UUIDs may be compared directly, as may two 32-bit UUIDs or two 128-bit UUID s. If two UUIDs of differing sizes are to be compared, the shorter UUID must be converted to the longer UUID fo rmat before comparison. 


在蓝牙中,每个服务和服务属性都唯一地由"全球唯一标识符" (UUID)来校验。正如它的名字所暗示的,每一个这样的标识符都要在时空上保证唯一。

UUID类可表现为短整形(16或32位)和长整形(128 位)UUID。

UUID值被固定分配在某个范围,该范围的第一个数值称为蓝牙UUID基数(Bluetooth_Base_UUID),其值为00000000—0000—1000—8000—00805F9B34FB。在此范围中,UUID用一个 16位或32位的二进制数表示,经常被称作16位或32位UUID。它的实际值代表一个 128位数。

128位的UUID值与16位或32位的UUID值之间的换算关系如下: 

128_bit_value=16_bit_value*2^96+Bluetooth_Base_UUID 

128_bit_value=32_bit_value*2^96+BIuetooth_Base_UUID

16位的UUID可以通过扩展16个0转换成32位的UUID。如果两个UUID值位数相同,则可以直接比较,如果位数不同,则需按照上述关系,将短UUID转换成长UUID,位数相同后再比较。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值