如何找到101b显示多少次? [英] How can I find how many times does 101b show in the number?

查看:84
本文介绍了如何找到101b显示多少次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出序列101b以16位数字显示多少次.但是我还需要找到距离较远的那些.

I need to find out how many times does the sequence 101b shows in a 16 bit number. But I need to find also the ones that are far away.

例如:在数字01010101中,它出现4次.因为3是它的一部分,而第四个(如果索引0是左位)则由索引1、4和7的3位组成.

For example: in the number 01010101 it appears 4 times. Because 3 are part of it and the fourth one (if index 0 is the left bit) is composed of the 3 bits at index 1, 4, and 7.

因为您可以将其关联为对称的101b序列.

Because you can relate to it as symmetrical 101b sequence.

这看起来真的很复杂,但是真的吗?我认为这可能有点棘手.

It seems really complicated, but does it really? I think it might just be a little tricky.

我设法找出了它定期显示的次数,例如您在示例编号中看到的3次.但是我不知道如何找到对称的. 我的老师的意思是轮换,我误解了这个问题,尽管感谢大家的帮助

I managed to find out how many times it shows regularly, like the 3 that you can see in the example number. But I don't know how can I find the symmetrical ones. My teacher did mean rotation and I misunderstood the problem, thanks for everyone for the help though

    mov cx,15
Check:

    push dx;the number that I need to check
    and dx,0111b
    cmp dx,101b
    jne Again
Again:

    pop dx
    shr dx,1
    loop check

推荐答案

类似这样的东西(未经测试):

somthing like this (not tested):

mov dx, yourNumber
mov cx, 16
xor ax, ax
count:
  mov bx, dx
  and bx, 0b111
  cmp bx, 0b101
  jne nope
     inc ax
  nope:
  rol dx, 1
  dec cx
  jnz count

因此,基本上,将寄存器旋转16次,并在每次迭代中进行测试,以通过用0b111屏蔽寄存器来降低最低3位是否等于0b101.经过此计算后,结果在ax中,而您测试的数字仍应在dx

so basically, you rotate the register 16 times and on each iteration to test, if the lowest 3 bits by masking the register with 0b111 are equal to 0b101. after this calculation, the result is in ax and the number you tested should be still in dx

这篇关于如何找到101b显示多少次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆