Пример #1
0
/* multree - construct tree for l [* /] r */
static Tree multree(int op, Tree l, Tree r) {
	Type ty = inttype;

	if (isarith(l->type) && isarith(r->type)) {
		ty = binary(l->type, r->type);
		l = cast(l, ty);
		r = cast(r, ty);		
	} else
		typeerror(op, l, r);
	return simplify(op, ty, l, r);
}
Пример #2
0
int tsFreePhoneImplementation::b_cat(char *ascii, CONFIG *config)
{
	KEY *key0;

	if((key0 = binary(ascii,broad_cats,config->broad_cats_num)))
		return(key0->keycount);
	else {
		fprintf(stderr,"Something gone wrong with broad_cats\n");
		return(-10);
	}
}
Пример #3
0
void ImageViewer::on_actionMake_Binary_triggered_t()
{
    cv::Mat cvMat = ASM::QPixmapToCvMat(QPixmap::fromImage(*image));
    cv::Mat grayscaleMat (cvMat.size(), CV_8U);
    cv::cvtColor( cvMat, grayscaleMat, CV_BGR2GRAY );
    cv::Mat binary(grayscaleMat.size(), grayscaleMat.type());

    cv::threshold(grayscaleMat, binary, popup_binary->GetValueBox(0), 255.0, cv::THRESH_BINARY);

    imageLabel->setPixmap(ASM::cvMatToQPixmap(binary).copy());
}
Пример #4
0
void SkypekitTestEngine::TransportSendRTPPacket(const void *data, int len) {
	Sid::Binary binary((char *)data, len);
	m_pCb->SendRTPPacket(binary);

	m_SendPcnt++;
	m_SendBStat.Update(len);
	if (m_SendBStat.IsValid())
		TI_DBG("Send bitrate: %s", m_SendBStat.GetStatStr());

	PACKET_DBG("From Anxb->RTP: packet len %d bytes, count: %d", len, m_SendPcnt);
}
Пример #5
0
    std::pair<GLenum,std::vector<char>> Program::getBinary() const
    {
      GLint binaryLength(0);
      glGetProgramiv( getGLId(), GL_PROGRAM_BINARY_LENGTH, &binaryLength );

      GLenum binaryFormat(0);
      std::vector<char> binary(binaryLength);
      glGetProgramBinary( getGLId(), binaryLength, nullptr, &binaryFormat, binary.data() );

      return( std::make_pair( binaryFormat, binary ) );
    }
Пример #6
0
void SkypekitTestEngine::TransportSendFrame(VideoData &frame) {
	Sid::Binary binary((char *)frame.Data(), frame.Size());
	m_pCb->SendFrame(binary, frame.GetTimestamp());

	m_SendFcnt++;
	m_SendBStat.Update(frame.Size());
	if (m_SendBStat.IsValid())
		TI_DBG("Send bitrate: %s", m_SendBStat.GetStatStr());

	PACKET_DBG("TransportSendFrame: packet len %d bytes, count: %d", frame.Size(), m_SendFcnt);
}
int main(){
    int cas, N, M,k;
    int bcount, hcount;
    scanf("%d",&cas);
    while(cas--){
        scanf("%d",&N);
        M = N;
        bcount=hcount=0;
        bcount = binary(N);
        while(M){
            k = M%10;
            hcount = hcount+binary(k);
            M = M/10;
        }

        printf("%d %d\n",bcount,hcount);


    }
    return 0;
}
Пример #8
0
/** Trinkles the stretches when the adjacent stretches are already trusty.
 *
 * @param array   description of array to sort
 * @param r       root of the stretch
 * @param stretch description of stretches to trinkle
 */
static void semitrinkle(array const *array, size_t r, stretch s)
{
  size_t r1 = r - s.c;

  DEBUG(("semitrinkle(%p, %zu, (%u, %s))\n", array, r, s.b, binary(s.p)));

  if (array->less(array->m, r, r1)) {
    DEBUG(("\tswap(%p @%zu <=> @%zu b=%u)\n", array, r, r1, s.b));
    array->swap(array->m, r, r1);
    trinkle(array, r1, s);
  }
}
Пример #9
0
int power(int n, int k)
{
  int cnt=binary(k);
  compute(n,cnt);
  ull res=1;
  int i=0;
  for(i=0;i<LIMIT;++i)
    if(positions[i]) 
      res=(res*powers[i])%PRIME;

  return (int)res%PRIME;
}
Пример #10
0
int main(void)
{
	unsigned long n;
	printf("输入一个正整数进行测试:(q to quit)");
	while(scanf("%ld",&n)==1){
		printf("n的二进制形式是:");
		binary(n);
		printf("\n继续测试:");
	}	
	printf("测试结束!\n");
	return 0;
}
Пример #11
0
/*
	look-up vocabulary word in lex-ordered table.  words may have
	two entries with different codes. if minimum acceptable value
	= 0, then return minimum of different codes.  last word CANNOT
	have two entries(due to binary sort).
	word is the word to look up.
	val  is the minimum acceptable value,
		if != 0 return %1000
*/
int vocab(char *word, int val)
{
	int	v1, v2;

	if ((v1 = binary(word, wc, MAXWC)) >= 0) {
		v2 = binary(word, wc, MAXWC-1);
		if (v2 < 0)
			v2 = v1;
		if (!val)
			return(wc[v1].acode < wc[v2].acode\
			       ? wc[v1].acode : wc[v2].acode);
		if (val <= wc[v1].acode)
			return(wc[v1].acode % 1000);
		else if (val <= wc[v2].acode)
			return(wc[v2].acode % 1000);
		else
			return(-1);
	}
	else
		return(-1);
}
Пример #12
0
int main(){

	printf("Enter the Decimal number: ");
	int decimal;

	scanf("%d",&decimal);

	int answer = binary(decimal);
	printf("\n\nbinary: %d\n" , answer);

	return 0;
}
Пример #13
0
    void matchNumeric() const {
        givenACodeSampleToTokenize nonNumeric("abc", true);
        ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%"));

        givenACodeSampleToTokenize binary("101010b", true);
        ASSERT_EQUALS(true, Token::Match(binary.tokens(), "%num%"));

        givenACodeSampleToTokenize octal("0123", true);
        ASSERT_EQUALS(true, Token::Match(octal.tokens(), "%num%"));

        givenACodeSampleToTokenize decimal("4567", true);
        ASSERT_EQUALS(true, Token::Match(decimal.tokens(), "%num%"));

        givenACodeSampleToTokenize hexadecimal("0xDEADBEEF", true);
        ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%"));

        givenACodeSampleToTokenize floatingPoint("0.0f", true);
        ASSERT_EQUALS(true, Token::Match(floatingPoint.tokens(), "%num%"));

        givenACodeSampleToTokenize doublePrecision("0.0d", true);
        ASSERT_EQUALS(true, Token::Match(doublePrecision.tokens(), "%num%"));

        givenACodeSampleToTokenize signedLong("0L", true);
        ASSERT_EQUALS(true, Token::Match(signedLong.tokens(), "%num%"));

        givenACodeSampleToTokenize negativeSignedLong("-0L", true);
        ASSERT_EQUALS(true, Token::Match(negativeSignedLong.tokens(), "- %num%"));

        givenACodeSampleToTokenize positiveSignedLong("+0L", true);
        ASSERT_EQUALS(true, Token::Match(positiveSignedLong.tokens(), "+ %num%"));

        givenACodeSampleToTokenize unsignedInt("0U", true);
        ASSERT_EQUALS(true, Token::Match(unsignedInt.tokens(), "%num%"));

        givenACodeSampleToTokenize unsignedLong("0UL", true);
        ASSERT_EQUALS(true, Token::Match(unsignedLong.tokens(), "%num%"));

        givenACodeSampleToTokenize unsignedLongLong("0ULL", true);
        ASSERT_EQUALS(true, Token::Match(unsignedLongLong.tokens(), "%num%"));

        givenACodeSampleToTokenize positive("+666", true);
        ASSERT_EQUALS(true, Token::Match(positive.tokens(), "+ %num%"));

        givenACodeSampleToTokenize negative("-42", true);
        ASSERT_EQUALS(true, Token::Match(negative.tokens(), "- %num%"));

        givenACodeSampleToTokenize negativeNull("-.0", true);
        ASSERT_EQUALS(true, Token::Match(negativeNull.tokens(), "- %num%"));

        givenACodeSampleToTokenize positiveNull("+.0", true);
        ASSERT_EQUALS(true, Token::Match(positiveNull.tokens(), "+ %num%"));
    }
Пример #14
0
void SaveDatabase::go()
{
    cout << "Enter the filename: ";
    string filename = "";

    while(filename.empty())
        getline(cin, filename);

    ofstream binary(filename.c_str(), std::fstream::out | std::fstream::trunc);
    db.WriteToBinary(binary);
    binary.close();
    cout << "Saving successful" << endl << endl;
}
int main()
{
 int t;
 long a,b,d;
scanf("%d",&t);
while(t--)
{
  scanf("%ld %ld",&a,&b);
  d=binary(flag,b,0,38)-bin(flag,a,0,38);
  printf("%ld\n",d);
}
  return(0);
}
Пример #16
0
main()
{
	link *head = NULL;
	link *temp = NULL;
	add(&head, 1);
	add(&head, 2);
	add(&head, 3);
	add(&head, 4);
	print(head);
	temp = reverse(head);
	print(temp);
	binary(100);
}
/*void powerset(int num[],int n){
  int len=pow(2,n);
  int bin[len];
  for(i=0;i<len;i++){
  binary(i,bin);
  for(j=0;j<n;j++){
  if(bin[j]==1){
  printf("%d",a[j]);
  }
  }
  printf("\n");
  }
  }*/
int main(){
	int a[4];
	int i;
	for(i=0;i<4;i++){
		scanf("%d",&a[i]);
	}
	int *b;
	b=binary(2,a);
	printf("%d\n",*b);
	printf("%x",&b[0]); //x is for hexadecimal

	return 0;
}
int main(){
    int N;
    while(scanf("%d",&N)==1 && N!=0){
        memset(rem,-1,sizeof(rem));
        printf("The parity of ");
        int count = binary(N);
        for(int k=i-1; k>=0; k--){
            printf("%d",rem[k]);
        }
        printf(" is %d (mod 2).\n",count);
    }
    return 0;
}
Пример #19
0
Tree condtree(Tree e, Tree l, Tree r) {
	Symbol t1;
	Type ty, xty = l->type, yty = r->type;
	Tree p;

	if (isarith(xty) && isarith(yty))
		ty = binary(xty, yty);
	else if (eqtype(xty, yty, 1))
		ty = unqual(xty);
	else if (isptr(xty)   && isnullptr(r))
		ty = xty;
	else if (isnullptr(l) && isptr(yty))
		ty = yty;
	else if (isptr(xty) && !isfunc(xty->type) && isvoidptr(yty)
	||       isptr(yty) && !isfunc(yty->type) && isvoidptr(xty))
		ty = voidptype;
	else if ((isptr(xty) && isptr(yty)
		 && eqtype(unqual(xty->type), unqual(yty->type), 1)))
		ty = xty;
	else {
		typeerror(COND, l, r);
		return consttree(0, inttype);
	}
	if (isptr(ty)) {
		ty = unqual(unqual(ty)->type);
		if (isptr(xty) && isconst(unqual(xty)->type)
		||  isptr(yty) && isconst(unqual(yty)->type))
			ty = qual(CONST, ty);
		if (isptr(xty) && isvolatile(unqual(xty)->type)
		||  isptr(yty) && isvolatile(unqual(yty)->type))
			ty = qual(VOLATILE, ty);
		ty = ptr(ty);
	}
	switch (e->op) {
	case CNST+I: return cast(e->u.v.i != 0   ? l : r, ty);
	case CNST+U: return cast(e->u.v.u != 0   ? l : r, ty);
	case CNST+P: return cast(e->u.v.p != 0   ? l : r, ty);
	case CNST+F: return cast(e->u.v.d != 0.0 ? l : r, ty);
	}
	if (ty != voidtype && ty->size > 0) {
		t1 = genident(REGISTER, unqual(ty), level);
	/*	t1 = temporary(REGISTER, unqual(ty)); */
		l = asgn(t1, l);
		r = asgn(t1, r);
	} else
		t1 = NULL;
	p = tree(COND, ty, cond(e),
		tree(RIGHT, ty, root(l), root(r)));
	p->u.sym = t1;
	return p;
}
Пример #20
0
/**
 * Print all of a program's parameters/fields to given file.
 */
static void
_mesa_fprint_program_parameters(FILE *f,
                                struct gl_context *ctx,
                                const struct gl_program *prog)
{
   GLuint i;

   fprintf(f, "InputsRead: 0x%llx (0b%s)\n",
           (unsigned long long) prog->InputsRead, binary(prog->InputsRead));
   fprintf(f, "OutputsWritten: 0x%llx (0b%s)\n",
                 (unsigned long long)prog->OutputsWritten, 
		 binary(prog->OutputsWritten));
   fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
   fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
   fprintf(f, "NumParameters=%d\n", prog->NumParameters);
   fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
   fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
   fprintf(f, "IndirectRegisterFiles: 0x%x (0b%s)\n",
           prog->IndirectRegisterFiles, binary(prog->IndirectRegisterFiles));
   fprintf(f, "SamplersUsed: 0x%x (0b%s)\n",
                 prog->SamplersUsed, binary(prog->SamplersUsed));
   fprintf(f, "Samplers=[ ");
   for (i = 0; i < MAX_SAMPLERS; i++) {
      fprintf(f, "%d ", prog->SamplerUnits[i]);
   }
   fprintf(f, "]\n");

   _mesa_load_state_parameters(ctx, prog->Parameters);

#if 0
   fprintf(f, "Local Params:\n");
   for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
      const GLfloat *p = prog->LocalParams[i];
      fprintf(f, "%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
   }
#endif	
   _mesa_print_parameter_list(prog->Parameters);
}
Пример #21
0
bool binary(int key, int *array, int min, int max)
{
    if (max < min)
    {
        return false;
    }
    else
    {
        int mid = findMid(min, max);
        if (array[mid] < key)
        {
            return binary(key, array, mid + 1, max);
        }
        else if(array[mid] > key)
        {
            return binary(key, array, min, mid - 1);
        }
        else
        {
            return true;
        }
    }
}
ProgramBinary * ProgramBinaryImplementation_GetProgramBinaryARB::getProgramBinary(const Program * program) const
{
    int length = program->get(GL_PROGRAM_BINARY_LENGTH);

    if (length == 0)
        return nullptr;

    GLenum format;
    std::vector<char> binary(length);

    glGetProgramBinary(program->id(), length, nullptr, &format, binary.data());

    return new ProgramBinary(format, binary);
}
Пример #23
0
int main(){
    int cas;while(~scanf("%d",&cas)){
        while(cas--){
            int n,m;
            scanf("%d%d",&n,&m);
            for(int i=0;i<m;i++){
                scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
            }
            int ans=binary(0,m,n);
            printf("%d\n",ans);
        }
    }
    return 0;
}
Пример #24
0
/**
 * Returns true if value is in array of n values, else false.
 */
bool search(int value, int values[], int n)
{
    int min = 0;
    int max = n;
    bool check = binary(value, values, min, max);
    if (check == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main()
{
    int n,len,i,j,num,sum,hexa;
    char m[10];
    scanf("%d",&n);
    getchar();
    for(i=0; i<n; i++)
    {
        hexa = 0;
        scanf("%s",m);
        sscanf(m,"%d",&num);
        b1 = binary(num);
        len = strlen(m)-1;
        for(j=len; j>=0; j--)
        {
            hexa+= (m[j]-'0') * pow(16,(len-j));
        }
        m[j]='\0';
        b2 = binary(hexa);
        printf("%d %d\n",b1,b2);
    }
    return 0;
}
Пример #26
0
int main(){
     int n, maxn, len;
     while(~scanf("%d", &n) && n != 0){
          for(int i = 1; i <= n; i++)    scanf("%lld", data + i);  
          minlis[1] = data[1]; LIS[1] = 1; len = 1;
          for(int i = 2; i <= n; i++){
                LIS[i] = binary(1, len, data[i]); 
                minlis[LIS[i]] = data[i]; 
                if(LIS[i] > len)  len++;
          }
          minlis[1] = data[n];  LDS[n] = 1; len = 1;
          for(int i = n-1; i > 0; i--){
                LDS[i] = binary(1, len, data[i]);   
                minlis[LDS[i]] = data[i];    
                if(LDS[i] > len)   len++;
          }
          maxn = 0;
          for(int i = 1; i <= n; i++)
               maxn = max(maxn , LIS[i] + LDS[i] - 1);                   
          printf("%d\n", n - maxn);
     }
     return 0;
}
Пример #27
0
void main()
{
 int list[20],i,n,x;
 clrscr();
 printf("\nEnter the size:");
 scanf("%d",&n);
 printf("\nEnter the list:");
 for(i=0;i<n;++i)
  scanf("%d",&list[i]);
 printf("\nEnter the element to be searched:");
 scanf("%d",&x);
 binary(list,0,n-1,x);
 getch();
}
Пример #28
0
    std::pair<GLenum, std::unique_ptr<char[]>> ShaderProgram::getBinary() const
    {
        if(ext::programBinary())
        {
            GLenum format = 0;
            std::unique_ptr<char[]> binary(new char[getBinarySize()]);

            glCheck(glGetProgramBinary(program_, getBinarySize(), nullptr, &format, void_cast(binary)));

            return std::make_pair(format, std::move(binary));
        }
        else
            return std::make_pair(0, nullptr);
    }
Пример #29
0
/*************************************************
* Decode a BigInt                                *
*************************************************/
BigInt BigInt::decode(const byte buf[], u32bit length, Base base)
{
    BigInt r;
    if(base == Binary)
        r.binary_decode(buf, length);
#ifndef BOTAN_MINIMAL_BIGINT
    else if(base == Hexadecimal)
    {
        SecureVector<byte> hex;
        for(u32bit j = 0; j != length; ++j)
            if(Hex_Decoder::is_valid(buf[j]))
                hex.append(buf[j]);

        u32bit offset = (hex.size() % 2);
        SecureVector<byte> binary(hex.size() / 2 + offset);

        if(offset)
        {
            byte temp[2] = { '0', hex[0] };
            binary[0] = Hex_Decoder::decode(temp);
        }

        for(u32bit j = offset; j != binary.size(); ++j)
            binary[j] = Hex_Decoder::decode(hex+2*j-offset);
        r.binary_decode(binary, binary.size());
    }
#endif
    else if(base == Decimal || base == Octal)
    {
        const u32bit RADIX = ((base == Decimal) ? 10 : 8);
        for(u32bit j = 0; j != length; ++j)
        {
            byte x = Charset::char2digit(buf[j]);
            if(x >= RADIX)
            {
                if(RADIX == 10)
                    throw Invalid_Argument("BigInt: Invalid decimal string");
                else
                    throw Invalid_Argument("BigInt: Invalid octal string");
            }

            r *= RADIX;
            r += x;
        }
    }
    else
        throw Invalid_Argument("Unknown BigInt decoding method");
    return r;
}
Пример #30
0
/*************************************************
* Encode a BigInt                                *
*************************************************/
void BigInt::encode(byte output[], const BigInt& n, Base base)
{
    if(base == Binary)
        n.binary_encode(output);
#ifndef BOTAN_MINIMAL_BIGINT
    else if(base == Hexadecimal)
    {
        SecureVector<byte> binary(n.encoded_size(Binary));
        n.binary_encode(binary);
        for(u32bit j = 0; j != binary.size(); ++j)
            Hex_Encoder::encode(binary[j], output + 2*j);
    }
#endif
    else if(base == Octal)
    {
        BigInt copy = n;
        const u32bit output_size = n.encoded_size(Octal);
        for(u32bit j = 0; j != output_size; ++j)
        {
            output[output_size - 1 - j] = Charset::digit2char(copy % 8);
            copy /= 8;
        }
    }
    else if(base == Decimal)
    {
        BigInt copy = n;
        BigInt remainder;
        copy.set_sign(Positive);
        const u32bit output_size = n.encoded_size(Decimal);
        for(u32bit j = 0; j != output_size; ++j)
        {
            divide(copy, 10, copy, remainder);
            output[output_size - 1 - j] =
                Charset::digit2char(remainder.word_at(0));
            if(copy.is_zero())
            {
                if(j < output_size - 1)
                {
                    int extra = output_size - 1 - j;
                    memmove(output, output + extra, output_size - extra);
                    memset(output + output_size - extra, 0, extra);
                }
                break;
            }
        }
    }
    else
        throw Invalid_Argument("Unknown BigInt encoding method");
}