循环移位Ç [英] circular shift c

查看:188
本文介绍了循环移位Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为int一个地方转移到右侧,并将其返回

在Java中,我可以只返回N >> 1;

这是可能用C?

我们得到的方法是如下

  //返回N A右循环1位后移
unsigned int类型right_circular_shift_1(无符号整数N){


解决方案

C没有一个循环移位,所以我猜的行使来实现它。到了左循环移位做到这一点的方法是:

   - 获得当前最左边的位,并将其保存
- 一个向左移动光标数
- 或者在最右边的比特位置的保存位

对于右循环移位:

   - 获得当前最右边的位,并将其保存
- 一个向右移动数
- 或者在最左边位的位置的保存位

I have to shift the int one place to the right and return it

In Java i can just return n >> 1;

Is this possible in C?

The method we were given is as follows

// Return n after a right circular 1-bit shift
unsigned int right_circular_shift_1(unsigned int n) {

解决方案

C does not have a circular shift, so I guess the exercise is to implement it. The way to do this for a left circular shift is to:

- get the current leftmost bit  and save it
- shift the number leftwards by one
- or the saved bit in at the rightmost bit position

For a right circular shift:

- get the current rightmost bit  and save it
- shift the number rightwards by one
- or the saved bit in at the leftmost bit position

这篇关于循环移位Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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