| |

VerySource

 Forgot password?
 Register
Search
View: 998|Reply: 6

How to get any unsigned long

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-2 11:00:01
| Show all posts |Read mode
Given parameter m, 0 <= m <= 23
How to get any m bits of unsigned long, 0 or 1
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Brazil

Post time: 2020-5-12 16:30:01
| Show all posts
For example, take M bits
  unsigned long x = 122;
  x >> (m-1)
  x&&000000000000000000000001
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-12 18:15:02
| Show all posts
Rotate right >>, the last one can be 1
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-14 08:00:01
| Show all posts
Or define a union
union
{
int i;
IntBit0: 1
IntBit1: 1
...
IntBit31: 1
}
Then you can get it.
Reply

Use magic Report

0

Threads

18

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-5-14 09:15:01
| Show all posts
for (i = 0; i <32; i ++)
  temp = (m >> i)&0x00000001;
Reply

Use magic Report

0

Threads

25

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-5-14 12:30:01
| Show all posts
The upstairs is pretty good.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-20 09:00:01
| Show all posts
Haha, is n’t it?

unsigned long x;
x&(1 << m)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list