int main(int argc, char** argv) { int count = (argc > 1 ? atoi(argv[1]) % 128 : 128); uint17 X = 0; uint19 Y = 0; uint36 Z = 0; srand(count); for (int i = 0; i < count; i++) { Y = X = 0; for (int j = 0; j < bitwidthof(X); j++) { X <<= 1; X += (rand() % 2 == 0 ? 0 : 1); } for (int j = 0; j < bitwidthof(Y); j++) { Y <<= 1; Y += (rand() % 2 == 0 ? 0 : 1); } Z = bit_concat(X, Y); printf("bit_concat("); printBits(X); printf("(%d),",int(X)); printf(","); printBits(Y); printf("(%d)) = ",int(Y)); printBits(Z); printf("\n"); } return 0; }
void test2() { unsigned int a = 9; printf("a:\n"); printBits(a); setBitAt(&a, 10, 1); printf("a after setBitAt(&a,10,1):\n"); printBits(a); setBitAt(&a, 20, 1); printf("a after setBitAt(&a,20,1):\n"); printBits(a); setBitAt(&a, 0, 0); printf("a after setBitAt(&a,0,0):\n"); printBits(a); setBitAt(&a, 3, 0); printf("a after setBitAt(&a,3,0):\n"); printBits(a); }
int main() { int a=125; printBits(a); a = turnoff(a,4); printBits(a); }
int main(int argc, const char* argv[]) { srand(time(NULL)); int i = rand(); // creates two random 2 byte ints and assigns them to a 4 byte long int long int l = (rand() << 31) | rand(); int test_output = test(i, l); printf("i: %d", i); printf("\n"); printf("l: %ld", l); printf("\n"); printf("\n"); printf("int i: %d", i); printf("\n"); printBits(sizeof(i), &i); printf("\n"); printf("long int l: %ld", l); printf("\n"); printBits(sizeof(l), &l); printf("\n"); printf("int l: %d", (int)l); printf("\n"); printBits(sizeof((int)l), &l); printf("\n"); printf("test_output: %d", test_output); printf("\n"); return 0; }
int main(int argc, char** argv) { #ifdef ENABLE_LARGE_INTEGERS BitType Y = X * X; #else BitType Y = X; #endif srand(0); unsigned i, j; printf("Selecting bits from: "); printBits(X); printf("\n"); for (i = 0; i < bitwidthof(BitType); ++i) { BitType left = rand() % bitwidthof(BitType); BitType right = i; printf("part_select(Y,%3u,%3u) = ", (unsigned)right, (unsigned)left); BitType Z = part_select(Y, right, left); printBits(Z); uint64_t val = Z; printf(" (%llx)", val); printf("\n"); } return 0; }
int main() { int i = 1; int ir = reverse(1); printf("%d\n", i); printf("%d\n", ir); printBits(sizeof(i), &i); printBits(sizeof(ir), &ir); return 0; }
int main() { long *p = malloc(sizeof(long*)); printBits(p); printf("\n%p\n", p); p = set_state((int*) p, IFLAG); printBits(p); int *nobits = get_ptr(p); printf("\n"); printBits(nobits); return 1; }
//************************************************************************** ipage_t::ipage_t() { int check_mask = maskBits32( ~0, 0, IPAGE_PAGE_BITS - 1 ); if (check_mask != IPAGE_PAGE_MASK) { DEBUG_OUT("error: page mask set incorrectly\n"); DEBUG_OUT("it is : "); printBits(IPAGE_PAGE_MASK); DEBUG_OUT("should be : "); printBits(check_mask); } memset( m_instr, 0, sizeof(static_inst_t *) * IPAGE_MAX_INSTR ); }
main() { short i,j,neg,k; printf("enter the negative value\n"); scanf("%d",&neg); printf("\n"); k=neg; printBits(k); k=~neg; printf("\n"); k++; printBits(k); }
void display_world () { // Draws world to the screen for (i=0; i<32; i++) { if(is_world_calc){ printBits(sizeof(uint32_t), (world_calc+i)); } else{ printBits(sizeof(uint32_t), (world_write+i)); } } printf("--------------------------------\n"); }
void test4() { unsigned int a = 0x6F245FF2; unsigned int b = 0x7F67FF89; printf("a:\n"); printBits(a); printf("countBits(a,1)=%d\n", countBits(a,1)); printf("countBits(a,0)=%d\n", countBits(a,0)); printf("b:\n"); printBits(b); printf("countBits(b,1)=%d\n", countBits(b,1)); printf("countBits(b,0)=%d\n", countBits(b,0)); }
int main(int argc, char **argv) { unsigned x = atoi(argv[1]); int n = atoi(argv[2]); unsigned result = rightrot(x, n); printBits(sizeof(result), &result); }
void testToggleBit() { cout << endl; cout << "Test toggleBit():" << endl; cout << "=================" << endl; unsigned int n = 0; for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); } for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); } }
int main(int argc, char** argv) { int i; printf("0b0"); printBits(X); printf("\n"); for (i = bitwidthof(BitType); i > 0; --i) { X = part_set(X, 1, i-1, i-1); printf("0b0"); printBits(X); printf("\n"); } return 0; }
int main(int argc, char** argv) { uint68 x = 0xF0F0F0F0F0F0F0F0ULL; uint60 y = 0x0F0F0F0F0F0F0F0FULL; uint68 z = part_set(x, y, 0, (bitwidthof(y)-1)); uint68 z2= part_set(x, y, (bitwidthof(y)-1), 0); printf("x = "); printBits(x); printf("\ny = "); printBits(y); printf("\npart_set(x, y, 0, 59) = "); printBits(z); printf("\npart_set(x, y, 59, 0) = "); printBits(z2); printf("\n"); return (int) z; }
main() { int num,x,y; printf("enter the value\n"); scanf("%d",&num); /*bits before shifting*/ printf("value before shifting:%d\n",num); printBits(num); printf("\n"); /***left shifting**/ num=num<<1; printf("value after shifting:%d\n",num); printBits(num); printf("\n %d \n",num); }
void printBitmap() { int j; if(bitmap == NULL) loadBitmap(); printf("\n ********** BITMAP MAP ************\n"); printf("\n ****[0] -> b7 b6 b5 b4 b3 b2 b1****\n"); printf("\n ****[1] -> .............. b9 b8****\n"); printf("\n ***********************************\n"); for(j=0;j<128;j++) { printf( "[%3d] -> ", j); printBits(sizeof(bitmap[j]),&bitmap[j]); printf( "| "); if(j%4==3 && j != 0) printf( "\n"); } printf("\n ***********************************\n"); }
int main(int argc, char* argv[]) { unsigned int x = 1; printf ("little or big?\n"); printf ("%d\n", (int) (((char *)&x)[0])); int n = 180482; printBits(sizeof(n), &n); int m = n >> 16; m |= n >> 8; m |= n >> 4; m |= n >> 2; m |= n >> 1; m &= 1; printBits(sizeof(m), &m); return 0; }
void printBits(unsigned int num) { if (num == 0) { printf("Bit pattern is: "); } else { printBits(num/2); printf("%d",num%2); } }
int main() { Block blk; int i; for (i = 0; i < 8; i++) { blk.byte[i] = 0xFE; } printf("Original Data: \n"); for (i = 0; i < 8; i++) { printBits(blk.byte[i]); } printf("\n"); unsigned char lastBits = GetLastTwoBits(&blk); unsigned char exFKey = 0xFF; unsigned char firstBits = GetFirstTwoBits(&blk); //we try to xor the last bits with feistel key, then xor the first bits with the resulting feisteled lastBits = lastBits ^ exFKey; firstBits = firstBits ^ lastBits; ModifyLastTwoBits(&blk, lastBits); ModifyFirstTwoBits(&blk, firstBits); printf("Using ex Feistel Key 0xFF\n"); printf("Result before shift: \n"); for (i = 0; i < 8; i++) { printBits(blk.byte[i]); } printf("\n"); printf("Result after shift left: \n "); CircularShiftLeft(&blk); for (i = 0; i < 8; i++) { printBits(blk.byte[i]); } printf("\n"); printf("Result after shift right: \n"); CircularShiftRight(&blk); for (i = 0; i < 8; i++) { printBits(blk.byte[i]); } printf("\n"); }
void testCountOneBits() { cout << endl; cout << "Test countOneBits():" << endl; cout << "====================" << endl; unsigned int n = 0; for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); cout << "Number of 1 bits = " << countOneBits(n) << endl; } for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); cout << "Number of 1 bits = " << countOneBits(n) << endl; } }
int main (int argc, char**argv) { int ii = 0; unsigned long long val; printf("sizeof: %d\n", sizeof(unsigned long long)); for(ii =0; ii < 8*(sizeof(unsigned long long)); ++ii) { val = ~((unsigned long long)0) >> ii; printf("%02d: ", ii); printBits(sizeof(unsigned long long), &val); printf(" %llu\n", val); } for(ii =0; ii < 8*(sizeof(unsigned long long)); ++ii) { val = ((unsigned long long)1) << ii; printf("%02d: ", ii); printBits(sizeof(unsigned long long), &val); printf(" %llu\n", val); } return 0; }
int main(int argc, char **argv) { typedef uint256 BitType; BitType X = -1; printf("uint256 X = -1 -> "); printBits(X); printf("\n"); return (int) X; }
void printBits(unsigned int num) { static int i = 0; if(i == sizeof(num) * 8) { printf("\n"); return; } printf("%d", (num & (1 << (31 - i))) >> (31 - i)); i++; printBits(num); }
int decode_protocol4 (protocol4* self, unsigned long code) { printBits(sizeof(code), &code); unsigned int offsetadr = 0; self->address = (code & (((1 << 4) - 1) << offsetadr)) >> offsetadr; unsigned int offsetnet = 20; self->network = (code & (((1 << 3) - 1) << offsetnet)) >> offsetnet; unsigned int offsetmag = 4; self->magic = (code & (((1 << 16) - 1) << offsetmag)) >> offsetmag; return 0; }
int main(int argc, char** argv) { #ifdef ENABLE_LARGE_INTEGERS BitType Y = X * X; #else BitType Y = X; #endif srand(0); unsigned i, j; for (i = 0; i < bitwidthof(BitType); ++i) { BitType high = rand() % bitwidthof(BitType); BitType low = i; printf("part_select(Y, %3u, %3u) = ", (unsigned)low, (unsigned)high); BitType Z = part_select(Y, low, high ); printBits(Z); uint64_t val = Z; printf(" (%llx)", val); printf("\n"); } BitType Z = part_select(Y, 0, bitwidthof(Y)-1); if (Z == Y) printf(" True: "); else printf("False: "); printBits(Z); printf(" == "); printBits(Y); printf("\n"); return 0; }
void RTC_M41T62::printAllBits(){ WIRE.beginTransmission(M41T62_ADDRESS); WIRE._I2C_WRITE(0); WIRE.endTransmission(); WIRE.requestFrom(M41T62_ADDRESS, 16); for(int regCount = 0; regCount < 16; regCount++){ printBits(WIRE._I2C_READ()); Serial.print(" : 0x"); Serial.println(regCount, HEX); } // reset address pointer to 0 per datasheet note pg23 WIRE.beginTransmission(M41T62_ADDRESS); WIRE._I2C_WRITE(0); WIRE.endTransmission(); }
int main(int argc, char** argv) { uint250 x = 0xF0F0F0F0F0F0F0F0ULL; int result = 0; int i; srand(128); for (i = 0; i < 16; ++i) { x *= rand(); printf("x = 0b0"); printBits(x); printf("\n"); result = test_reduce_xor47(x) + test_reduce_xor68(x) + test_reduce_xor250(x); printf("Xor reductions of x = %d\n", result); } return 0; }
void test3() { unsigned int a = 0xFFFF1009; printf("a:\n"); printBits(a); int v = getBitAt(a, 3); printf("getBitAt(3)=%d\n", v); v = getBitAt(a, 10); printf("getBitAt(10)=%d\n", v); v = getBitAt(a, 20); printf("getBitAt(20)=%d\n", v); v = getBitAt(a, 5); printf("getBitAt(5)=%d\n", v); }
void printDesc(segment_descriptors* desc){ unsigned int base, limit; uint8_t* ptr = (uint8_t*)desc; base = desc->base_address_15_0 + (desc->base_address_23_16<<16) + (desc->base_address_31_24<<24); limit = desc->limit_15_0 + (desc->limit_19_16<<16); printf("__________________________________________\n"); printf("| Base |G|D|L|A|Limit|P|Pr|S|Type| Base |\n"); printf("| 31-24 |r|B| |v|19-16|r|iv|N| | 23-16 |\n"); printf("|");printBits(desc->base_address_31_24, 8); printf("|%u|%u|%u|%u|", desc->granularity, desc->operation_size, desc->fixed_value_bits, desc->available); printBits(desc->limit_19_16,4); printf(" |%u|", desc->present); printBits(desc->privilege,2); printf("|%u|", desc->descriptor_type); printBits(desc->type,4); printf("|"); printBits(desc->base_address_23_16,8); printf("| %x %x %x %x\n", *(ptr+7), *(ptr+6), *(ptr+5), *(ptr+4)); printf("_____________________________________________\n"); printf("| Base 15-0 | Limit 15-0 |\n"); printf("| "); printBits(desc->base_address_15_0,16); printf(" | "); printBits(desc->limit_15_0,16); printf(" | %x %x %x %x\n", *(ptr+3), *(ptr+2), *(ptr+1), *(ptr+0)); printf("---------------------------------------------\n"); printf("Base :\t0x%x\t\t(%u)\n", base, base); printf("Limit:\t0x%x\t\t(%u)\t", limit, limit); printf("%s\n", desc->granularity?"4kiB blocks":"bytes "); if(desc->descriptor_type){ printf("Type :\t%s\t", desc->type&8?"Code":"Data"); if(desc->type&8){ printf("%s\t%s\t", desc->type&4?"Conform ":"nonConform", desc->type&2?"Readable ":"nonReada "); }else{ printf("%s\t%s\t", desc->type&4?"ExpandDown":"ExpandUp ", desc->type&2?"Writable ":"nonWritable"); } printf("%s\n", desc->type&1?"Accessed":"nonAccessed"); } }