Esempio n. 1
0
int main(int argc, char* argv[]){
	
	if ( 1 && argc > 1) { 
		int n = atoi(argv[1]);
	
		int small = nearest_small(n);
		printf( "%.4i(%.4i)  ", small, count_ones(small) );	
		print_bits(small);
		
		int small2 = nearest_small2(n);
		printf( "%.4i(%.4i)  ", small2, count_ones(small) );	
		print_bits(small2);
		
		printf( "%.4i(%.4i)  ", n, count_ones(n) );			  
		print_bits(n);
		
		int large = nearest_large(n);
		printf( "%.4i(%.4i)  ", large, count_ones(large) );	
		print_bits(large);
		
		
		int large2 = nearest_large2(n);
		printf( "%.4i(%.4i)  ", large2, count_ones(large2) );	
		print_bits(large2);
	}	
  	
  exit(0);
}
Esempio n. 2
0
void test_bits(unsigned char *p) {
    p[0] = 10; p[1] = p[2] = p[3] = 0;
    p[4] &= ~15;
    p[4] |= 10;
    print_bits(36, p);
    print_bits(64, p);
}
Esempio n. 3
0
void
list_errors(int fd, struct pci_conf *p)
{
	uint32_t mask, severity;
	uint16_t sta, aer;
	uint8_t pcie;

	/* First check for standard PCI errors. */
	sta = read_config(fd, &p->pc_sel, PCIR_STATUS, 2);
	print_bits("PCI errors", pci_status, sta & PCI_ERRORS);

	/* See if this is a PCI-express device. */
	pcie = pci_find_cap(fd, p, PCIY_EXPRESS);
	if (pcie == 0)
		return;

	/* Check for PCI-e errors. */
	sta = read_config(fd, &p->pc_sel, pcie + PCIR_EXPRESS_DEVICE_STA, 2);
	print_bits("PCI-e errors", pcie_device_status, sta & PCIE_ERRORS);

	/* See if this device supports AER. */
	aer = pcie_find_cap(fd, p, PCIZ_AER);
	if (aer == 0)
		return;

	/* Check for uncorrected errors. */
	mask = read_config(fd, &p->pc_sel, aer + PCIR_AER_UC_STATUS, 4);
        severity = read_config(fd, &p->pc_sel, aer + PCIR_AER_UC_SEVERITY, 4);
	print_bits("Fatal", aer_uc, mask & severity);
	print_bits("Non-fatal", aer_uc, mask & ~severity);

	/* Check for corrected errors. */
	mask = read_config(fd, &p->pc_sel, aer + PCIR_AER_COR_STATUS, 4);
	print_bits("Corrected", aer_cor, mask);
}
Esempio n. 4
0
void test_getbits(unsigned x, int p, int n)
{
	printf("getbits(");
	print_bits(x);
	printf(", %d, %d) = ", p, n);
	print_bits(getbits(x, p, n));
	printf("\n");
} 
Esempio n. 5
0
int main()
{
	print_bits(127);
	print_bits(128);
	print_bits(0x00FF00FF);
	print_bits(0xFFFFFFFF);
	
	return 0;
}
Esempio n. 6
0
int main() {
  print_bits(0x12345678);
  printf("%d\n", bitcount(0x12345678));

  printf("\n");

  print_bits(0xd3adb33f);
  printf("%d\n", bitcount(0xd3adb33f));
}
Esempio n. 7
0
void test_setbits(unsigned x, int p, int n, unsigned y)
{
	printf("setbits(");
	print_bits(x);
	printf(", %d, %d, ", p, n);
	print_bits(y);
	printf(") = \n        ");
	print_bits(setbits(x, p, n, y));
	printf("\n");
}
Esempio n. 8
0
int main(void)
{
    int n = 7;
    int p = 16;
    unsigned x = ~0;

    printf("x before:       ");
    print_bits(x, sizeof(x));
    printf("x after invert: ");
    print_bits(invert(x, p, n), sizeof(x));

    return 0;
}
Esempio n. 9
0
int		main(void)
{	
	print_bits(130);
	ft_putchar('\n');
	reverse_bits(130);
	return (0);
}
Esempio n. 10
0
int main(int argc, char* argv[]) {

	int sum = 0;
	for(int i = 1; i < 1000000; i++) {
		char buffer[33];
		int dec_len = sprintf(buffer, "%i", i);

		//printf("%s\n", buffer);

		if(!is_palindrome(buffer, dec_len)) {
			continue;
		}

		memset(buffer, '\0', 33);
		print_bits(i, buffer, 33);
		char* bin = start(buffer, 32);
		if(bin == NULL) { printf("null\n"); return 0; }
		int bin_len = strlen(bin);

		//printf("%s\n", bin);

		if(!is_palindrome(bin, bin_len)) {
			continue;
		}

		sum += i;

	}

	printf("%i", sum);

	return 0;
}
void print_bits(int n){

	if(n>1)
		print_bits(n/2);

	printf("%d", n%2);
}
Esempio n. 12
0
int main( void ) {
	unsigned char result = clear_bitmask();
	printf( "The result is " );
	print_bits( result );
	printf( "\n" );
	return 0;
}
Esempio n. 13
0
void test_bitcount(unsigned int x)
{
    printf("bitcount(");
    print_bits(x);
    printf(") = %d = ", bitcount(x));
    printf("%d\n", bitcount2(x));
}
Esempio n. 14
0
/* Print huffman code properties assigned to character */
static void 
print_code(int character, struct hf_code code)
{
  printf("%c: %4d: ", character, code.size);
  print_bits(code.code);
  printf("\n");
}
Esempio n. 15
0
int		main(void)
{
	char a;

	a = 'c';
	print_bits(a);
	return (0);
}
Esempio n. 16
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    for (unsigned int i = 0; i < 256; ++i)
    {
        print_bits(i);
    }
    return 0;
}
Esempio n. 17
0
void print_value(float const & s)
{
	printf("%2.5f, ", s);
	print_bits(s);
	printf(", ");
//	print_11bits(detail::floatTo11bit(s));
//	printf(", ");
//	print_10bits(detail::floatTo10bit(s));
	printf("\n");
}
Esempio n. 18
0
void print_cursor_res(int i, NAMEINFO *info)
{
  CURSOR_NODE *node;
  CURSORIMAGE *image;
  int count;

  node = (CURSOR_NODE *)info->rcsdata;
  image = &(node->data);
  print_bmp_hdr("cursor", i, image->bmp_hdr);
  count = (int)bit_to_rgb(image->bmp_hdr->biBitCount);
  print_rgb_quad("cursor", i, image->rgb_quad, count);
  count = (image->bmp_hdr->biHeight * image->bmp_hdr->biWidth)/16;
  print_bits("cursor_xor_bits", i, (BYTE *)image->xor_mask, count);
  print_bits("cursor_and_bits", i, (BYTE *)image->and_mask, count);
  COUTPUT(( "static CURSORIMAGE cursor_data_%d = {\n",i));
  COUTPUT(("\t0x%04x, 0x%04x, ",image->wHotSpotX, image->wHotSpotY)); 
  COUTPUT(("cursor_bmp_hdr_%d, cursor_rgb_quad_%d, ", i, i));
  COUTPUT(("cursor_xor_bits_%d, cursor_and_bits_%d", i, i));
  COUTPUT(("};\n\n"));
}
Esempio n. 19
0
cx_vec input_state(char* input,Hamiltonian* h){
    int N = h->get_system_size();
    REP_TYPE state=string_to_state(input,N);
    cout <<"state is: "<<endl;
    print_bits(state,N);
    int pos =h->find_state(state);
    vec res=vec(zeros(h->get_dim()));
    res(pos)=1;
    cx_vec cres=cx_vec(res,zeros(h->get_dim()));
    return cres;
}
Esempio n. 20
0
void print_icon_res(int i, NAMEINFO *info)
{
  ICON_NODE *node;
  ICONIMAGE *image;
  int count;

  node = (ICON_NODE *)info->rcsdata;
  image = &(node->data);
  print_bmp_hdr("icon", i, image->icon_bmp_hdr);
  count = bit_to_rgb(image->icon_bmp_hdr->biBitCount);
  print_rgb_quad("icon", i, image->icon_rgb_quad, count);
  count = (int)(image->icon_bmp_hdr->biHeight * image->icon_bmp_hdr->biWidth * image->icon_bmp_hdr->biBitCount)/16;
  print_bits("icon_xor_bits", i, (BYTE *)image->icon_xor_mask, count);
  count = (image->icon_bmp_hdr->biHeight * image->icon_bmp_hdr->biWidth)/16;
  print_bits("icon_and_bits", i, (BYTE *)image->icon_and_mask, count);
  COUTPUT(( "static ICONIMAGE icon_data_%d = {\n",i));
  COUTPUT(("icon_bmp_hdr_%d, icon_rgb_quad_%d, ", i, i));
  COUTPUT(( "icon_xor_bits_%d, icon_and_bits_%d",i,i));
  COUTPUT(("};\n\n"));
}
Esempio n. 21
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    unsigned int numbers[] = { 64575, 1398101, 911, 262015 } ;

    for( unsigned int i = 0 ; i < sizeof(numbers) / sizeof( numbers[0] ) ; ++i )
    {
        const unsigned int n = numbers[i] ;
        printf( "%u is %sa binary palindrome. (", n, is_binary_palindrome(n) ? "" : "not " ) ;
        print_bits(n) ;
        puts( ")" ) ;
    }
}
Esempio n. 22
0
int main( void ) {
	unsigned char register_val[] = { 0x00, 0xff };

	for ( int i = 0; i < 2; i++ ) {
		unsigned char result = set_bits( register_val[i] );
		printf( "When register is 0x%02x, the result is ", register_val[i] );
		print_bits( result );
		printf( "\n" );
	}

	return 0;
}
Esempio n. 23
0
int main(int argc, char** argv) {
	char *data = (char *)align_malloc(100, 16);

	print_bits(data);

	data[0] = 'a';
	data[99] = 'b';

	std::cout << data[0] << " " << data[99] << std::endl;

	align_free(data);
}
Esempio n. 24
0
int main(int argc, char *argv[]) {
  const int size = sizeof(unsigned int) * 8;

  //  for (unsigned int i = 0; i < 20; ++i) {
  //    char buffer[size + 1] = {0};
  //    buffer[size] = '\0';
  //    btoa(i, buffer, size);
  //    printf("%3d: %s\n", i, buffer);
  //  }

  //  char buffer[size + 1] = {0};
  //  buffer[size] = '\0';
  //  unsigned int bf = 0x70;
  //  btoa(bf, buffer, size);
  //  printf("%3d: %s\n", bf, buffer);

  // bool isPowerOfTwo = x && !(x & (x - 1));

  // |= (1 << 2);

  // turn on 3rd bit from end (2^2)
  int x = 0;
  print_bits(x);
  x |= (1 << 2);
  print_bits(x);
  // turn it off
  x = 65535;
  print_bits(x);
  x &= ~(1 << 2);
  print_bits(x);

  if (is_little_endian()) {
    printf("This system is little endian.\n");
  } else {
    printf("This system is big endian.\n");
  }

  return EXIT_SUCCESS;
}
Esempio n. 25
0
void print_bytes(const uint8_t* bytes, const size_t size)
{
	size_t i;

	printf("showing bytes read:\nHEX    DEC    BIN");
	for(i = 0; i < size; ++i)
	{
		printf("\n$%02X    %3d    ", bytes[i], bytes[i]);
		print_bits(bytes[i]);
		
	}
	puts("\n--------------------------");
}
Esempio n. 26
0
// -----main関数はじまり-----
int main(void)
{
  unsigned no;
  int temp_no, snum;

  do {      // 非負の整数になるまで繰り返す
    printf("非負の整数を入力してください:");
    scanf("%d", &temp_no);
      } while (temp_no < 0);

  no = (unsigned)temp_no;

  do {      // 非負の整数になるまで繰り返す
    printf("何ビット目を変更しますか:");
    scanf("%d", &snum);
  } while (snum < 0);

  putchar('\n');

  // ここから出力開始
  printf("入力した数のビット表示 :");
  print_bits(no);
  putchar('\n');

  printf("%dビット目を1にした表示:", snum);
  print_bits(set(no, snum));
  putchar('\n');

  printf("%dビット目を0にした表示:", snum);
  print_bits(reset(no, snum));
  putchar('\n');

  printf("%dビット目を反転した表示:", snum);
  print_bits(inverse(no, snum));
  putchar('\n');

  return(0);
}
int main(){

	int a = 1024;
	int b = 19;

	printf("a = ");
	print_bits(a);
	printf("\n");

	printf("b = ");
	print_bits(b);
	printf("\n");	
	
	int start = 2;
	int end = 6;
	a = insert_bits(a, b, start, end);

	printf("Bits after inserting, a = ");
	print_bits(a);
	printf("\n");

	return 0;
}
int main(void) {
    UART_INIT_STDIO();

    // enable watchdog (pin 6 output)
    DDRD &= ~_BV(PIND6);
    blink(3);

    printf("\n");
    i2c_init(I2C_SPEED_400KHZ);
    for (uint8_t i = 0x00; i < 0x3a; i++) {
        uint8_t value = i2c_read_reg(0x6b, i);
        printf("REG(0x%02x) = ", i);
        print_bits(sizeof value, &value);
        printf(" 0x%02x\n", value);
    }

    i2c_write_reg(0x6b, 0x39, 0b00000000);
    uint8_t ctrl1 = i2c_read_reg(0x6b, 0x20);
    i2c_write_reg(0x6b, 0x20, ctrl1 | 0b1010);

    // do some low level blinking until the watchdog hits
    while (1) {
        uint8_t status = i2c_read_reg(0x6b, 0x27);
        print_bits(sizeof status, &status);
        printf(" X(%d) Y(%d) Z(%d), REF(%02x) TEMP(%02dºC)\r",
               i2c_read_reg16(0x6b, 0x28),
               i2c_read_reg16(0x6b, 0x2A),
               i2c_read_reg16(0x6b, 0x3C),
               i2c_read_reg(0x6b, 0x25),
               i2c_read_reg(0x6b, 0x26)
        );

        PORTB ^= _BV(PORTB5);
        _delay_ms(50);
    };
}
Esempio n. 29
0
/* Formata a exibição dos bits do inteiro dado. */
void mostra_bits_IEE754(int n) {
    float f;

    /* f = n;*/ /* implica que f recebe o valor armazenado em n, ou seja, os
                 * bits de n são lidos, interpretados como um inteiro de
                 * determinado valor. Este valor é então armazenado conforme o
                 * padrão IEEE754. A ideia deste exemplo é verificar o valor que
                 * a sequência de bits (definida por n) representa as ser
                 * interpretada como ponto flutuante. */

    memcpy(&f, &n, sizeof(f)); /* copia os bits de n em f. */

    printf("%f: ", f); /* mostra o valor de f */
    print_bits(n);     /* mostra os bits de n/f */
    putchar('\n');
}
Esempio n. 30
0
int main( void ) {
	unsigned char register_val[] = {
		0x00,
		0xff,
		(1 << 3) | (1 << (3 + 1) ) | ( 1 << ( 3 - 1) ),
		(1 << (3 + 1) ) | ( 1 << ( 3 - 1) ),
	};

	for ( int i = 0; i < (sizeof(register_val) / sizeof(unsigned char)); i++ ) {
		unsigned char result = read_bit( register_val[i] );
		printf( "When register is 0x%02x, the result is ", register_val[i] );
		print_bits( result );
		printf( "\n" );
	}

	return 0;
}