UVA 575-Skew Binary

本文介绍了如何将A-SkewBinary编码的数转换为十进制数,并提供了相应的C++代码实现。通过解析输入字符串并应用特定公式,可以轻松完成编码转换。
A - Skew Binary
Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu

Description

 
 

When a number is expressed in decimal, the k-th digit represents a multiple of10k. (Digits are numbered from right to left, where the least significant digit is number 0.) For example,

\begin{displaymath}81307_{10} = 8 \times 10^4 + 1 \times 10^3 + 3 \times 10^2 + ......mes 10^1 +7 \times 10 0 = 80000 + 1000 + 300 + 0 + 7= 81307.\end{displaymath}

When a number is expressed in binary, the k-th digit represents a multiple of2k. For example,

\begin{displaymath}10011_2 = 1 \times 2^4 + 0 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 +1 \times 2^0 = 16 + 0 + 0 + 2 + 1 = 19.\end{displaymath}

In skew binary, the k-th digit represents a multiple of2k+1 - 1. The only possible digits are 0 and 1, except that the least-significant nonzero digit can be a 2. For example,

\begin{displaymath}10120_{skew} = 1 \times (2^5 - 1) + 0 \times (2^4-1) + 1 \tim......2 \times (2^2-1) + 0 \times (2^1-1)= 31 + 0 + 7 + 6 + 0 = 44.\end{displaymath}

The first 10 numbers in skew binary are 0, 1, 2, 10, 11, 12, 20, 100, 101, and 102. (Skew binary is useful in some applications because it is possible to add 1 with at most one carry. However, this has nothing to do with the current problem.)

Input 

The input file contains one or more lines, each of which contains an integer n. If n = 0 it signals the end of the input, and otherwise n is a nonnegative integer in skew binary.

Output 

For each number, output the decimal equivalent. The decimal value of n will be at most 231 - 1 = 2147483647.

Sample Input 

10120
200000000000000000000000000000
10
1000000000000000000000000000000
11
100
11111000001110000101101102000
0

Sample Output 

44
2147483646
3
2147483647
4
7
1041110737


题目大意:

给你一个斜二进制的数,叫你算出他的十进制。


题目解析:

这题很简单没什么难度,把字符串转化为数字。再按照题目所给的公式,计算输出就好了。


#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main() {
	string num;
	while(cin>>num) {
		if(num == "0")
			break;
		int len = num.size();
		long long sum = 0;
		int tmp;
		for(int i=0;i<len;i++) {
			tmp = num[i]-'0';
			sum += tmp * (pow(2,len-i) - 1);
		}
		cout<<sum<<endl;	
	}
	return 0;
}

### PCIe Lane-to-Lane De-Skew 的原理及实现方法 PCIe 是一种高速串行通信协议,广泛应用于计算机内部的高速设备连接中。由于 PCIe 支持多 Lane(通道)传输,因此必须解决不同 Lane 之间信号到达时间不一致的问题,即 Lane-to-Lane Skew(时序偏移)。为了确保数据在接收端能够正确对齐,PCIe 定义了 Lane-to-Lane De-Skew 机制来补偿这种时序偏差[^2]。 在 PCIe 链路训练过程中,接收端通过检测特定的符号(Ordered Sets)来识别和校正 Lane 之间的偏移。例如,在链路初始化阶段,设备会发送 TS1 和 TS2 有序集(Ordered Set),这些符号包含 Lane 对齐所需的信息。接收端通过比较不同 Lane 上 TS1 和 TS2 的到达时间,计算出偏移量,并据此调整数据路径中的延迟,使得所有 Lane 的数据最终在时间上对齐[^3]。 对于 Gen1 和 Gen2 的 PCIe 版本,采用 COM(Comma)字符作为 De-Skew 的基准符号。如果 COM 字符没有同时出现在所有 Lane 上,接收端会将先到达的 COM 字符进行短暂延迟,以实现 Lane 同步。然而,这种机制只能校正较小的偏移,若偏移超过一定范围,则无法有效补偿。例如,在 2.5 GT/s 的速率下,最大可校正偏移为 20 纳秒,而一个标准的 SKP Ordered Set 长度为 16 纳秒,通常足以满足对齐需求[^1]。 在更高版本的 PCIe 中(如 Gen3 及以上),由于数据速率大幅提升,对 Lane 对齐的要求也更高。此时,除了使用 TS1 和 TS2 有序集外,还引入了更复杂的同步机制,包括使用特定的符号序列和缓冲策略,以确保即使在高速传输下也能实现精确的 Lane 对齐。这些机制通常依赖于接收端的弹性缓冲(Elastic Buffer)来吸收 Lane 之间的时序差异,并通过硬件逻辑进行动态调整[^2]。 以下是实现 Lane-to-Lane De-Skew 的一个典型硬件逻辑伪代码示例: ```verilog // 接收端检测 TS1/TS2 有序集并进行对齐 always @(posedge clk) begin if (rx_data == TS1_OS || rx_data == TS2_OS) begin lane_aligned <= 1'b1; lane_skew <= calculate_skew(); delay_buffer <= lane_skew; end end // 根据检测到的偏移量调整数据路径 function integer calculate_skew(); integer skew; skew = current_time - expected_time; return skew; endfunction ``` 该代码片段展示了接收端如何检测特定符号并计算偏移量,随后根据该偏移量调整数据路径中的缓冲延迟,以实现 Lane 对齐。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值