[Explanations] bitset, substr use [P1100 low bit exchange]

bitset, substr using P1100 low bit exchange

/ *
Expand
subject description
given a 2 ^ {32} 2 is less than
32
positive integers. This number may be a number of binary representation of 3232 (less than 3232 with 00 supplement). We said that before 1616 the binary number is "high", after 1616 as "low." It's low bit exchange, we can get a new number. How this new number is the number (in decimal).

For example, the number 13145201314520 represented as 000000000001 0,100,000,011,101,101 100000000000000101000000111011011000 (added 1,111 preamble 00 make up to 3232) in binary, in which the first 1616 is high, i.e. 000000000001 01000000000000010100; after 1616 is low, i.e., 0000 11101101 10000000111011011000. It's high and low exchange, we get a new binary number 0000 1110 1101 1,000,000,000,000,001 010000001110110110000000000000010100. It decimal 249036820249036820 that is.

Input format
a 2 ^ {32} 2 is less than
32
positive integers

Output format of
the new digital output

Sample Input Output
Input # 1 replication
1,314,520
output copy # 1
249 036 820
* /

/*
reference:
    
translation:
    
solution:

trigger:
    
note:
    *
record:

date:
    2019.09.07
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dwn(i,a,b) for(int i=a;i>=b;--i) 
template <typename T> inline void rd(T &x){x=0;char c=getchar();int f=0;while(!isdigit(c)){f|=c=='-';c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x=f?-x:x;} 
inline void write(int n){if(n==0)return;write(n/10);putchar(n%10+'0');}
#define mem(a,b) memset(a,b,sizeof(a))
#define ee(i,u) for(int i=head[u];i;i=e[i].next)

#undef int
int main(){
#define int long long
    #ifdef WIN32
    freopen("","r",stdin);
    #endif
    unsigned int x;rd(x);
    bitset<32>s(x);
    string now=s.to_string();
//  cout<<now<<endl;
    string head=now.substr(0,16);
    string tail=now.substr(16,16);
    string new_=tail+head;
//  cout<<new_<<endl;
//  printf("%d\n",tail.length());
    bitset<32>ans(new_);
 //   unsigned long long anns=ans.to_ullong();
    printf("%lld",ans.to_ullong());//一定要转化成unsigned long long,不然最高位为1的时候会变成负数 
    return 0;
}

Guess you like

Origin www.cnblogs.com/sjsjsj-minus-Si/p/11634762.html