[C + + basic] bit operation application--Create GUID

Source: Internet
Author: User

/*| (bitwise OR): X|y=z (z>=x, y), think of X, y bits one by one alignment, only corresponding to 1, take 1, and finally get the greater value of x, Y. "|" You can simply think of the operation operator & (bitwise AND) to get a larger value: X|y=z (z<=x, y), think of X, y bits one by one alignment, only corresponding to 0, take 0, and finally get the smaller value of x, Y. "&" can simply be considered as the operation operator >> (bitwise right SHIFT) to get a smaller value: X|y=z, think of x bits right shift y-bit (do not have the idea of a decimal point, think it is a pair of small points, hey, it has been bothering me), that is, from the end of x bits to erase y bits << (bitwise left): X|y=z, think of X's bits to the left Y-position, that is, at the end of x bits increase y 0. *///rgb color Merge int colormerge (int r,int g,int b) {//24-bit RGB value =R accounted for 8-bit +g accounted for 8-bit +b accounted for 8 bits//At bits end of R 16 0, added 8 0 at the end of bits of G, and finally, R, G, B of each A BITS take 1 return r << 16 | G << 8 | b;} RGB color split void colorseparate (int rgb) {///24-bit RGB value =R accounted for 8-bit +g 8-bit +b accounted for 8-bit int r = RGB >>16;//strip end 16 bits int g = RGB >>8 & 0xff;//0xff-->255--> consists of 8 1 bits, minus 8 bits at the end, int b = RGB & 0xFF;} UInt64 Createobjid (int platfromid,int serverid,int curtime,int seed) {//Create GUID//bits, seed (random seed) occupies 16 bits, curtime ( Timestamp) accounted for 32 bits, ServerID (server ID) accounted for 8 bits, PLATFROMID (platform ID) was randomly accounted for 8, total 64 bits UInt64 GUID = ((platfromid) << (8+32+16)) | ((ServerID) << (32 + 16)) | ((curtime) <<16) | ((Seed) (&AMP;0XFFFF); return GUID;}

[C + + basic] bit operation application--Create GUID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.