objective c - XCode bit array: selectedSegmentIndex to decimal -


so have 3 selectedsegmentindex. let's call them s1, s2, s3.

they in order going left right, each index of 2 (0 , 1). convert chosen index each segment , convert them integer. example:

s1.selectedsegmentindex = 0; s2.selectedsegmentindex = 1; s3.selectedsegmentindex = 1; 

this represents 011 in binary or 3 in decimal. going selectedsegmentindex decimal easy because add them up: s1.selectedsegmentindex*4 + s2.selectedsegmentindex*2 + s3.selectedsegmentindex, yields 3. part i'm having trouble going integer , fill out these 3 selectedsegmentindex. want take stab @ this? thanks!

use >> desired bit position 0, , use & turn off other bits.

s1.selectedsegmentindex = (bits >> 2) & 1; s2.selectedsegmentindex = (bits >> 1) & 1; s3.selectedsegmentindex = (bits >> 0) & 1; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -