简体   繁体   English

多少年的毫秒时间戳可用41位表示?

[英]How many years of millisecond timestamps can be represented by 41 bits?

I'm looking at the Instagram blog post about sharded ID generation . 我正在看Instagram关于分片ID生成的博客文章 This blog post describes generating 64-bit identifiers. 此博客文章描述了生成64位标识符。 Their mechanism allocates 41 of the 64 bits to a millisecond timestamp, and they say: 他们的机制将64位中的41位分配给毫秒时间戳,他们说:

  • 41 bits for time in milliseconds (gives us 41 years of IDs with a custom epoch) 41位时间(以毫秒为单位)(使用自定义纪元为我们提供41年的ID)

Is this a typo? 这是拼写错误吗? I calculated that you can store 69 years of millisecond timestamps in 41 bits. 我计算出你可以存储41位的69年毫秒时间戳。 Here's how: 这是如何做:

  • Max milliseconds stored in 41 bits: (2^41)-1 = 2199023255551 ms 存储在41位中的最大毫秒数:(2 ^ 41)-1 = 2199023255551 ms
  • Divided by (1000 * 60 * 60 * 24 * 365 ) ms/year = 69 years 除以(1000 * 60 * 60 * 24 * 365)ms /年= 69年

So, where am I wrong? 那么,我错在哪里?

You're not wrong about the calculation. 你对计算没错。

(2^41)-1 ms
    == 2199023255.551 s
    == 610839.7932086 hr 
    == 25451.65805036 days 
    == 69.6828 Julian years 
    == 69.6843 Gregorian Years

Which lines up closely with your result ( 69 years ). 哪个与您的结果密切相关( 69 years )。

However, the website you link to does say that 41 bits gives them 但是,您链接到的网站确实说41 bits给出了它们

41 years of IDs with a custom epoch 带有自定义纪元的41年ID

"Epoch" in this context is probably referring to the start date. 在这种情况下,“Epoch”可能指的是开始日期。 Given that that article was published "3 years ago", or in 2012 , we can calculate that their epoch begins in 2012 + 41 - 69 == 1984 . 鉴于该文章发表于“3年前”或2012 ,我们可以计算出他们的时代始于2012 + 41 - 69 == 1984 This date was possibly chosen as a reference . 这个日期可能被选为参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置N个位数时,可以表示多少个Int32数字? - How many Int32 numbers can be represented when N number of bits is set? 如何表示自然数以提供恒定的时间加法? - How can natural numbers be represented to offer constant time addition? 将许多位转换为Base 10 - Converting many bits to Base 10 如何找到两个服务器时间戳之间的时差? - How can I find time difference between two server timestamps? 如何修改此功能以考虑“月”和“年”? - How can I modify this function to take into account “months” and “years”? 以圆圈表示的图形可视化:如何 - Graph Visualization Represented in a Circle: How To 如何将浮点数转换为由字节分子和分母表示的最接近的分数? - How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator? 如何计算有多少个大小为n的位序列(设置了k个位,并且位值发生c次变化)? - How to calculate how many bit sequences of size n with k bits set and c changes of bit values exist? 如何将TimeSpan舍入为一位数毫秒 - How to round a TimeSpan to one digit for millisecond 如何创建像手机一样的秒/毫秒计时器? - How to create a second/millisecond timer like phone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM