+int count_pieces(unsigned int bitfield){
+ int count=0;
+ unsigned int n = bitfield;
+ while (n){
+ count += n & 1U;
+ n >>= 1U ;
+ }
+ return count;
+}
+
+int peer_has_not_piece(peer_t peer, unsigned int piece){
+ return !(peer->bitfield & 1U<<piece);
+}
+
+/** Check that a piece is not currently being download by the peer. */
+int peer_is_not_downloading_piece(peer_t peer, unsigned int piece){
+ return !(peer->current_pieces & 1U<<piece);
+}
+
+void get_status(char **status, unsigned int bitfield){
+ for(int i=FILE_PIECES-1; i>=0; i--)
+ (*status)[i] = (bitfield & (1U << i)) ? '1' : '0';
+ (*status)[FILE_PIECES] = '\0';
+}
+