/* * Load a two-color cursor into a crtc, performing rotation as needed */ static void xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src) { ScrnInfoPtr scrn = crtc->scrn; xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; CARD8 *cursor_image; #ifdef ARGB_CURSOR crtc->cursor_argb = FALSE; #endif if (crtc->rotation == RR_Rotate_0) cursor_image = src; else { int x, y; int xin, yin; int stride = cursor_info->MaxWidth >> 2; cursor_image = xf86_config->cursor_image; memset(cursor_image, 0, cursor_info->MaxHeight * stride); for (y = 0; y < cursor_info->MaxHeight; y++) for (x = 0; x < cursor_info->MaxWidth; x++) { xf86_crtc_rotate_coord (crtc->rotation, cursor_info->MaxWidth, cursor_info->MaxHeight, x, y, &xin, &yin); if (get_bit(src, cursor_info, xin, yin, FALSE)) set_bit(cursor_image, cursor_info, x, y, FALSE); if (get_bit(src, cursor_info, xin, yin, TRUE)) set_bit(cursor_image, cursor_info, x, y, TRUE); } } crtc->funcs->load_cursor_image (crtc, cursor_image); }
/* * Load a two color cursor into a driver that supports only ARGB cursors */ static void xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src) { ScrnInfoPtr scrn = crtc->scrn; xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; int x, y; int xin, yin; int stride = cursor_info->MaxWidth >> 2; int flags = cursor_info->Flags; CARD32 bits; #ifdef ARGB_CURSOR crtc->cursor_argb = FALSE; #endif for (y = 0; y < cursor_info->MaxHeight; y++) for (x = 0; x < cursor_info->MaxWidth; x++) { xf86_crtc_rotate_coord (crtc->rotation, cursor_info->MaxWidth, cursor_info->MaxHeight, x, y, &xin, &yin); if (get_bit (src, stride, flags, xin, yin, TRUE) == ((flags & HARDWARE_CURSOR_INVERT_MASK) == 0)) { if (get_bit (src, stride, flags, xin, yin, FALSE)) bits = xf86_config->cursor_fg; else bits = xf86_config->cursor_bg; } else bits = 0; cursor_image[y * cursor_info->MaxWidth + x] = bits; } crtc->funcs->load_cursor_argb (crtc, cursor_image); }
/**************************************************************************** * 関数名 : get_bits * 作成日 : * 作成者 : S.Kobayashi * 更新日 : * 機能 : ファイルからn bit読み込む関数 * 引数 : 対象ファイル:fp, 読み込むbit数:n * 戻り値 : int型の値:value ****************************************************************************/ int get_bits(FILE* fp,int n){ int i,v,value = 0; for(i = n-1; i>=0; i--){ /* byteのi番目を入力 */ v = get_bit(fp); if(v == EOF){ return value; } else if(v > 0){ value |= (1 << i); /* ループが終わると値が格納されている */ } } return value; }
static void end_badly () { die_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); if (test_connected == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); if (test_sending == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase did not send any messages before timeout\n"); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", msg_sent, msg_scheduled, msg_recv, msg_recv_expected); if (test_send_timeout == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test had timeout while waiting to send data\n"); int i; for (i = 0; i < TOTAL_MSGS; i++) { if (get_bit (bitmap, i) == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); ok = -1; } } if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (cc != NULL) GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); if (p2 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); ok = GNUNET_SYSERR; }
main() { char bit_vector[5000]={0}; int i; set_bit(2,bit_vector); set_bit(3,bit_vector); set_bit(4,bit_vector); set_bit(227,bit_vector); set_bit(500,bit_vector); for(i=0;i<5000;i++) { if(get_bit(i,bit_vector))printf("%d is present\n",i); } }
/* if the string is not a member return 0 otherwise return a non-zero if it is a member, * the non-zero value return has no meaning! */ word_type is_member(membership_type *membership, char *value, word_type is_present) { char_type *string = (char_type *)value; word_type hash = hashing_function(membership)(string, hashing_func_parameters(membership)); /* if we are not tracking statistics just return the bit value, if present its value will be non-zero, if 0 its not present. */ #ifndef TRACK_STATISTICS return get_bit(bit_field(membership), hash); /* return the actual bit which is 0 or 1,2,4,8, .... */ #else if (get_bit(bit_field(membership), hash)) /* we got a hit. */ { if (!is_present) /* but we weren't expecting it. */ membership->number_of_false_positives++; /* increase count and return 1 */ return 1; } if (is_present) { membership->number_of_false_negatives++; printf("WARNING!! false negative '%s'\n", string); } return 0; #endif }
u32 TIM0_u8ReadOF(void) { if(get_bit(TIFR,TOV0)) { set_bit(TIFR,TOV0); TIM0_OFCOUNT++ ; } //DELAY(100); return (TIM0_OFCOUNT *TIM0_u8TIME_OVFLW ) ; }
int geohash_decode(const GeoHashRange* lat_range, const GeoHashRange* lon_range, const GeoHashBits* hash, GeoHashArea* area) { if (NULL == hash || NULL == area || NULL == lat_range || NULL == lon_range) { return -1; } area->hash = *hash; uint8_t i = 0; area->latitude.min = lat_range->min; area->latitude.max = lat_range->max; area->longitude.min = lon_range->min; area->longitude.max = lon_range->max; for (; i < hash->step; i++) { uint8_t lat_bit, lon_bit; lon_bit = get_bit(hash->bits, (hash->step - i) * 2 - 1); lat_bit = get_bit(hash->bits, (hash->step - i) * 2 - 2); if (lat_bit == 0) { area->latitude.max = (area->latitude.max + area->latitude.min) / 2; } else { area->latitude.min = (area->latitude.max + area->latitude.min) / 2; } if (lon_bit == 0) { area->longitude.max = (area->longitude.max + area->longitude.min) / 2; } else { area->longitude.min = (area->longitude.max + area->longitude.min) / 2; } } return 0; }
int main (int argc, char **argv) { n = strtol(argv[1], NULL, 10); int numthreads = strtol(argv[2], NULL, 10); clock_t start, end; double elapsed; // Find number of ints needed to store n in bits //int onlyoddn = n / 2; int intsforbitarray = (n / 32) + 1; primes = malloc (intsforbitarray * sizeof(int)); base = 3; printf("Need %d for n= %d\n", intsforbitarray, n); // Start timer start = clock(); pthread_t threads[numthreads]; int rc; long t; void *status; for (t = 0; t < numthreads; t++) { printf("Started thread %d \n", t); rc = pthread_create(&threads[t], NULL, worker, (void *) base); if (rc) { printf("ERROR; return code from pthread_create() is %d \n", rc); exit(-1); } } for (int i = 0; i < numthreads; i++) { rc = pthread_join(threads[i], &status); } // Include 2 manually, since we don't check even numbers printf("Primes less than %d are: 2 ", n); for (int i = 3; i < n; i += 2) { if (get_bit(primes, i) == 0) { printf("%d ", i); } } printf("\n"); //End timer end = clock(); elapsed = (double)(end - start) / CLOCKS_PER_SEC; printf("Execution time: %f\n", elapsed); pthread_exit(NULL); }
static void end_badly () { unsigned int i; die_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Stopping peers\n"); if (test_connected == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peers got connected\n"); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); if (test_sending == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase did not send any messages before timeout\n"); if (test_send_timeout == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test had timeout while waiting to send data\n"); for (i = 0; i < TOTAL_MSGS; i++) { if (get_bit (bitmap, i) == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %u\n", i); ok = -1; } } if (th != NULL) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; } if (cc != NULL) { GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); if (p2 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); ok = GNUNET_SYSERR; }
/* Get a symbol */ int huffrecv(Node *node, int *ch, byte *fin) { while(node && node->symbol == INTERNAL_NODE){ if(get_bit(fin)) node = node->right; else node = node->left; } if(!node){ return 0; /* comerrorf(ERR_DROP, "Illegal tree!"); */ } return (*ch = node->symbol); }
static Data build_delta_string(OE oe, List proof_tasks, XORcommitResult xom, byte and_challenge) { Data result = Data_new(oe,(proof_tasks->size()+7)/8); uint i =0 ; for (i = 0; i < proof_tasks->size();++i) { ProofTask pt = proof_tasks->get_element(i); uint j = 0; byte delta = 0; uint lind = pt->value >> 1; for( j = 0; j < lind;++j) { delta ^= get_bit(xom->m0,pt->indicies[j]); } set_bit(result->data,i,delta); } return result; }
inline void rx_get_preamble(void) { rx_packet->current_preamble = 0; while(rx_packet->current_preamble != (int) VLC_PREAMBLE){ rx_packet->current_preamble = (rx_packet->current_preamble >> 1) | (get_bit() << 31); if(rx_packet->current_preamble == (int) VLC_ACK){ if(tx_packet->state == TX_WAITING_ACK) tx_packet->state = PACKET_COMPLETE; } } rx_packet->state = RX_GETTING_SEQUENCE; }
/* Allocates new color pair. Returns new pair index, or -1 on failure. */ static int allocate_pair(int fg, int bg) { int i; for(i = 0; i < avail_pairs; i++) { if(!get_bit(color_pair_map, i)) { init_pair(FCOLOR_BASE + i, fg, bg); set_bit(color_pair_map, i); break; } } return (i < avail_pairs) ? (FCOLOR_BASE + i) : -1; }
static void test3(void) { static bit_array bits[SIZE(20)] = {0}; char2bits(bits, 0, 'B'); char2bits(bits, 8, 'C'); assert(bits2char(bits, 0) == 'B'); assert(bits2char(bits, 8) == 'C'); for (size_t i = 16; i < 20; i++) { assert(get_bit(bits, i) == 0); } printf("Test3 Passed!\n"); }
/** \brief Given an integer val encoded in n bits (boolean variables), assert the constraint that val <= k. */ void assert_le_k(Z3_context ctx, Z3_solver s, unsigned n, Z3_ast * val, unsigned k) { Z3_ast i1, i2, not_val, out; unsigned idx; not_val = Z3_mk_not(ctx, val[0]); if (get_bit(k, 0)) out = Z3_mk_true(ctx); else out = not_val; for (idx = 1; idx < n; idx++) { not_val = Z3_mk_not(ctx, val[idx]); if (get_bit(k, idx)) { i1 = not_val; i2 = out; } else { i1 = Z3_mk_false(ctx); i2 = Z3_mk_false(ctx); } out = mk_ternary_or(ctx, i1, i2, mk_binary_and(ctx, not_val, out)); } // printf("at-most-k:\n%s\n", Z3_ast_to_string(ctx, out)); Z3_solver_assert(ctx, s, out); }
void read_mat () { memset (M, 0, sizeof M); scanf ("%s", str); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (get_bit ()) M[i][j] = true; else M[j][i] = true; } } }
int *modulate_am(char *data) { int i, j, k; int * vbuf = malloc(sizeof(int) * FRAME_BUFFER); for (i = 0; i < EF_SIZE; i++) for (j = 0; j < BITS_BYTE; j++) for (k = 0; k < BIT_SIZE; k++) { long index = i * BITS_BYTE * BIT_SIZE + j * BIT_SIZE + k; vbuf[index] = get_bit(data[i], (j + 1)) * WAV_AMPL * sin( ((double) index * PULSATION) / ((double) SAMPLE_RATE) ); } return vbuf; }
int main() { //Part 1. Evaluating Hash Functions int bloomsize = 100; int x; bloom_filter_t bloomfilter; bloom_init(&bloomfilter, bloomsize); printf ("Hash1: %i %i %i %i %i %i\n",hash1(&bloomfilter, 0),hash1(&bloomfilter, 1), hash1(&bloomfilter, 2),hash1(&bloomfilter, 3),hash1(&bloomfilter, 13), hash1(&bloomfilter, 97)); printf ("Hash2: %i %i %i %i %i %i\n",hash2(&bloomfilter, 0),hash2(&bloomfilter, 1), hash2(&bloomfilter, 2),hash2(&bloomfilter, 3),hash2(&bloomfilter, 13), hash2(&bloomfilter, 97)); bloom_destroy(&bloomfilter); //Part 2: printf("\nDoing Smoke Test.\n"); bloomsize = 1000; bloom_init(&bloomfilter, bloomsize); for (x= 0; x< 70; x++) { bloom_add(&bloomfilter, x); } int totalbits = 0; for (x = 0; x< bloomsize; x++) { totalbits += get_bit(&bloomfilter, x); } printf("Total bits set: %i\n",totalbits); bloom_destroy(&bloomfilter); //Part 3 printf("\nDoing N_HASHES Test.\n"); int array1[100]; int array2[100]; gen_rand(array1, 100, 1000000); gen_rand(array2, 100, 1000000); run_test3(array1, array2, 100); }
/* * Problem 02. Extract Bit from Integer * * Write an expression that extracts from given integer n the value of given * bit at index p. Examples: * * ------------------------------------------------ * n | binary representation | p | bit @ p | * ------------------------------------------------| * 5 | 00000000 00000101 | 2 | 1 | * ------------------------------------------------| * 0 | 00000000 00000000 | 9 | 0 | * ------------------------------------------------| * 15 | 00000000 00001111 | 1 | 1 | * ------------------------------------------------| * 5343 | 00010100 11011111 | 7 | 1 | * ------------------------------------------------| * 62241 | 11110011 00100001 | 11 | 0 | * ------------------------------------------------| */ int main() { uint32_t n; uint32_t p; printf("n = "); scanf("%u", &n); printf("p = "); scanf("%u", &p); printf("\nbit @ p\n"); printf("%d\n", get_bit(n, p)); return (EXIT_SUCCESS); }
iNode * fs_get_inode(int number){ int sector = number/4; int offset = number%4; iNode * ret = (iNode*)malloc(sizeof(iNode)); void * recieve = malloc(512); if ( get_bit(number, INODEMAP) != 0 ){ recieve = read_disk(vDisk->disk,INODETABLESECTOR + sector,recieve,BLOCK_SIZE,0); memcpy(ret,recieve + (128*offset),128); }else{ return NULL; } return ret; }
static void uf_zerofill_skipp_zero(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to, uchar *end) { if (get_bit(bit_buff)) bzero((char*) to,(uint) (end-to)); else { #ifdef WORDS_BIGENDIAN bzero((char*) to,rec->space_length_bits); decode_bytes(rec,bit_buff,to+rec->space_length_bits,end); #else end-=rec->space_length_bits; decode_bytes(rec,bit_buff,to,end); bzero((byte*) end,rec->space_length_bits); #endif } }
static void test2(void) { static bit_array bits[SIZE(40)] = {0}; hex2bits(bits, 0, 12450); hex2bits(bits, 16, 11037); assert(bits2hex(bits, 0) == 12450); assert(bits2hex(bits, 16) == 11037); for (size_t i = 32; i < 40; i++) { assert(get_bit(bits, i) == 0); } printf("Test2 Passed!\n"); }
int *modulate_fm(char *data) { int i, j, k; int index; uintmax_t suma = 0; int * vbuf = malloc(sizeof(int) * FRAME_BUFFER); for (i = 0; i < EF_SIZE; i++) for (j = 0; j < BITS_BYTE; j++) for (k = 0; k < BIT_SIZE; k++) { suma += get_bit(data[i], j + 1); index = i * BITS_BYTE * BIT_SIZE + j * BIT_SIZE + k; vbuf[index] = WAV_AMPL * sin( ((double)(PULSATION * index + PULSATION_DELTA * suma)) / SAMPLE_RATE ); } return vbuf; }
int fs_insert_inode(iNode * node) { int number = node->iNode_number; int sector = number / 4; int offset = number % 4; void * receive = (void *) malloc(BLOCK_SIZE); if (get_bit(number, INODEMAP) == 0) { set_bit(number, INODEMAP); } read_disk(0, INODETABLESECTOR + sector, receive, BLOCK_SIZE, 0); memcpy(receive + (128 * offset), node, 128); //+(128*offset) write_disk(0, INODETABLESECTOR + sector, receive, BLOCK_SIZE, 0); return number; }
/* 反转各位 */ static void reversc_bits(unsigned char *bits, unsigned long len) { unsigned long lbytes = bit_len_byte(len); unsigned char *tmp = (unsigned char *) alloca(lbytes); unsigned long c_bit; long c_byte = 0; memset(tmp, 0, lbytes); for (c_bit = 0; c_bit < len; ++c_bit) { unsigned int bitpos = c_bit % 8; if (c_bit > 0 && c_bit % 8 == 0) ++c_byte; tmp[c_byte] |= (get_bit(bits, len - c_bit - 1) << bitpos); } memcpy(bits, tmp, lbytes); }
static void end () { unsigned long long delta; char *value_name; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; FPRINTF (stderr, "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), "kb/s"); GNUNET_free (value_name); if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (cc != NULL) GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); ok = 0; int i; for (i = 0; i < TOTAL_MSGS; i++) { if (get_bit (bitmap, i) == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); ok = -1; } } }
static void uf_space_prespace(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to, uchar *end) { uint spaces; if (get_bit(bit_buff)) bfill((byte*) to,(end-to),' '); else { if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end) { bit_buff->error=1; return; } bfill((byte*) to,spaces,' '); if (to+spaces != end) decode_bytes(rec,bit_buff,to+spaces,end); } }
static void uf_endspace_selected(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to, uchar *end) { uint spaces; if (get_bit(bit_buff)) { if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end) { bit_buff->error=1; return; } if (to+spaces != end) decode_bytes(rec,bit_buff,to,end-spaces); bfill((byte*) end-spaces,spaces,' '); } else decode_bytes(rec,bit_buff,to,end); }
unsigned int cycle_bits(unsigned int x, unsigned int n) { unsigned int bitCycle = x; for(int i=1;i<=32;i++) { unsigned int position = (i+n)%32; unsigned int bitGet = (unsigned int) get_bit(x,i); bitCycle = set_bit(bitCycle,position,bitGet); } // la ligne suivante permet de faire échouer le test "test_cycle_bits" //return ~bitCycle; return bitCycle; }