如何在位域上执行插入操作?

时间:2017-11-22 15:52:54

标签: ios bit-fields

如何对位字段执行插入操作?

如果我有1111(整数15),我如何在" index"处插入0? 1到11101?

我在Swift 4中写作,我使用Int作为数据类型。

在这篇Stackoverflow文章中,他们展示了如何在位域上执行删除操作(它在java中,但这与语言无关):Removing bit at specific index

P.S。这是高性能代码。

1 个答案:

答案 0 :(得分:2)

您需要提取插入点下方的位以及上面的位。你需要将上面的位移位,然后重新组合这些部分。因此:

.background-image-container {
  display: flex;
  width: 100%;
  height: 350px;
}

.background-image {
  display: flex;
  width: 100%;
  min-height: 180px;
  max-height: 350px;
  height: inherit;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
}