コード例 #1
0
ファイル: block.cpp プロジェクト: AndreGleichner/coreclr
unsigned            BasicBlock::dspPreds()
{
    unsigned count = 0;
    for (flowList* pred = bbPreds; pred != nullptr; pred = pred->flNext)
    {
        if (count != 0)
        {
            printf(",");
            count += 1;
        }
        printf("BB%02u", pred->flBlock->bbNum);
        count += 4;

        // Account for %02u only handling 2 digits, but we can display more than that.
        unsigned digits = CountDigits(pred->flBlock->bbNum);
        if (digits > 2)
        {
            count += digits - 2;
        }

        // Does this predecessor have an interesting dup count? If so, display it.
        if (pred->flDupCount > 1)
        {
            printf("(%u)", pred->flDupCount);
            count += 2 + CountDigits(pred->flDupCount);
        }
    }
    return count;
}
コード例 #2
0
ファイル: ByteSink.cpp プロジェクト: DaveAckley/MFM
  void ByteSink::Print(s32 decimal, s32 fieldWidth, u8 padChar)
  {
    if (decimal < 0) {
      if (decimal-1 > 0) {
        // Argh.  Printing this one value right is a huge pain.
        if (padChar == '0' && fieldWidth > 11) {
          Print("-");
          for (s32 i = 11; i < fieldWidth; ++i)
            Print("0");
          Print("2147483648");
        } else
          Print("-2147483648", fieldWidth, padChar);
        return;
      }
      decimal = -decimal;

      u32 len = CountDigits((u32) decimal, 10) + 1;

      if (padChar == '0') WriteByte('-');
      while (fieldWidth > (s32) len) {
        WriteByte(padChar);
        --fieldWidth;
      }
      if (padChar != '0') WriteByte('-');
      fieldWidth = 0;
    }
    Print((u32) decimal, fieldWidth, padChar);
  }
コード例 #3
0
    bool isHappy(int n) {

        int count;

        if(n == 1)
        {
            return true;
        }

        while(1)
        {
            count = CountDigits(n);
            n = SumOfDigits(n,count);

            if(n == 1)
            {
                return true;
            }
            else if(n == 0)
            {
                return false;
            }
            else
            {
                do nothing
                }

        }
    }
コード例 #4
0
ファイル: test_Checksum.c プロジェクト: fossology/fossology
/**
 * \brief test function CountDigits
 * \test
 * -# Call CountDigits() with a number
 * -# Check if function returned actual count
 */
void testCountDigits()
{
  uint64_t Num = 15;
  int Digits = 0;
  Digits = CountDigits(Num);
  //printf("%d has %d digits\n",Num,Digits);
  FO_ASSERT_EQUAL(Digits, 2);
}
コード例 #5
0
ファイル: ByteSink.cpp プロジェクト: DaveAckley/MFM
/**
   Print \a num, in a format selected by \a code, to the current xmit packet of \a face.  The possible
   format codes are:

   - #DEC: Print one to ten bytes containing the base-10 representation of the 32 bits of \a num,
      using the ASCII characters '0' through '9'.  See the '%d' code in #packetScanf(u8 * packet,
      const char * format,...)  for a way to read in a value that was printed with code \c DEC, and
      in #facePrintf(u8 face, const char * format,...)  for an alternate way to print in this
      representation.
   - #HEX: Print one to eight bytes containing the base-16 representation of the 32 bits of \a num,
      using the ASCII characters '0' through '9' to represent 0 through 9, and 'A' through 'F' to
      represent 10 through 15.  See the '%x' code in #packetScanf(u8 * packet, const char *
      format,...) for a way to read in a value that was printed with code \c HEX, and in
      #facePrintf(u8 face, const char * format,...)  for an alternate way to print in this
      representation.
   - #OCT: Print one to eleven bytes containing the base-8 representation of the 32 bits of \a num,
      using the ASCII characters '0' through '7' to represent 0 through 7.  See the '%x' code in
      #packetScanf(u8 * packet, const char * format,...)  for a way to read in a value that was
      printed with code \c OCT, and in #facePrintf(u8 face, const char * format,...)  for an
      alternate way to print in this representation.
   - #BIN: Print one to 32 bytes containing the base-2 representation of the 32 bits of \a num,
      using the ASCII characters '0' and '1' to represent 0 and 1.  See the '%b' code in
      #packetScanf(u8 * packet, const char * format,...)  for a way to read in a value that was
      printed with code \c BIN, and in #facePrintf(u8 face, const char * format,...)  for an
      alternate way to print in this representation.
   - #B36: Print one to six bytes containing the base-36 representation of the 32 bits of \a num,
      using the ASCII characters '0' through '9' to represent 0 through 9, and 'A' through 'Z' to
      represent 10 through 35.  See the '%t' code in #packetScanf(u8 * packet, const char *
      format,...)  for a way to read in a value that was printed with code \c B36, and in
      #facePrintf(u8 face, const char * format,...)  for an alternate way to print in this
      representation.
   - #BEU32: Print exactly four bytes containing the 32 bits of \a num, with the four bytes in 'big
      endian order', also known as 'network order'.  See the '%l' code in #packetScanf(u8 * packet,
      const char * format,...) for a way to read in a value that was printed with code \c BEU32,
      and in #facePrintf(u8 face, const char * format,...)  for an alternate way to print in this
      representation.\n
      \c BEU32 is called a 'binary' code, but it must not be confused with #BIN.  With \c BEU32,
      each of the four output bytes may each contain any possible bit pattern, whereas with code
      #BIN each output byte is either the ASCII code for '0' or the ASCII code for '1'.
   - #BEU16: Print exactly two bytes containing the low-order 16 bits of \a num, with the two
      bytes in 'big endian order', also known as 'network order'.  See the '%h' code in
      #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was
      printed with code \c BEU16, and in #facePrintf(u8 face, const char * format,...)  for an
      alternate way to print in this representation.\n
      \c BEU16 is called a 'binary' code, but it must not be confused with #BIN.  With \c BEU16,
      each of the two output bytes may each contain any possible bit pattern, whereas with code #BIN
      each output byte is either the ASCII code for '0' or the ASCII code for '1'.
   - #BYTE: Print exactly one byte containing the low-order 8 bits of \a num.  See the '%c' code in
      #packetScanf(u8 * packet, const char * format,...) for a way to read in a value that was
      printed with code \c BYTE, and in #facePrintf(u8 face, const char * format,...)  for an
      alternate way to print in this representation.\n
      \c BYTE is called a 'binary' code, but it must not be confused with #BIN.  With \c BYTE, the
      output byte may each contain any possible bit pattern, whereas with code #BIN each output byte
      is either the ASCII code for '0' or the ASCII code for '1'.

   In addition to those codes, it is also possible to print in other bases between 2 and 36, if
   there is call to do so.  For example, using a \a code value of 13 will select printing in base
   13, using the ASCII characters '0' through '9' and 'A' through 'C'.

  \param num A 32 bit number to be printed in a particular format.

  \param code What format to use (see above).

  \fails BAD_FORMAT_ARG If \a code is an illegal code.  The legal codes are #BEU32, #BEU16 or
  #BYTE, or any value from 2 to 36 (which includes #DEC, #HEX, #OCT, #BIN, and #B36).

XXX UPDATE!
  Sample all-ASCII printable packet generation:
  \usage
  \code
    void myHandler(u8 *) {
      facePrint(SOUTH,"L 1234 in:");
      facePrint(SOUTH," base 10="); facePrint(SOUTH, 1234, DEC); // Prints 1234
      facePrint(SOUTH," base 16="); facePrint(SOUTH, 1234, HEX); // Prints 4D2
      facePrint(SOUTH," base 8=");  facePrint(SOUTH, 1234, OCT); // Prints 2322
      facePrint(SOUTH," base 2=");  facePrint(SOUTH, 1234, BIN); // Prints 10011010010
      facePrint(SOUTH," base 36="); facePrint(SOUTH, 1234, B36); // Prints YA
      facePrintln(SOUTH);
    }
  \endcode

XXX UPDATE
  Sample binary packet generation:
  \usage
  \code
    void setup() { /\* nothing to do *\/ }
    void loop() {                                  // Print a packet containing exactly eight bytes:
      facePrint(ALL_FACES,"t");                    //  1 byte containing an ASCII 't'
      facePrint(ALL_FACES,millis(),BEU32);        // +4 bytes of board uptime in big endian
      facePrint(ALL_FACES,random(10000),BEU16);  // +2 bytes of a random number 0..9999 in big endian
      facePrintln();                               // +1 byte containing an ASCII newline '\n'
      delay(1000);                                 // Wait a second, then do it again.
    }
  \endcode
 */
  void ByteSink::Print(u32 num, Format::Type code, s32 fieldWidth, u8 padChar)
  {

    switch (code) {
    case Format::LEX64:
    case Format::BEU64:
      FAIL(ILLEGAL_ARGUMENT);

    case Format::LEXHD:  // padding makes no sense for a lex header
      PrintLexDigits(num);
      break;

    case Format::LEX32:
    case Format::LXX32:
      {
        u32 base = 10;
        if (code==Format::LXX32)
          base = 16;

        u32 digits = CountDigits(num, base);
        if (fieldWidth > (s32) digits)
          digits = fieldWidth;

        PrintLexDigits(digits);
        Print(num, (Format::Type) base, fieldWidth, padChar);
        break;
      }

    case Format::BEU32:  // padding makes no sense for binary
      WriteByte((num>>24)&0xff);
      WriteByte((num>>16)&0xff);
      /* FALL THROUGH */

    case Format::BEU16:
      WriteByte((num>>8)&0xff);
      /* FALL THROUGH */

    case Format::BYTE:
      WriteByte((num>>0)&0xff);
      break;

    default:
      PrintInBase(num, (u32) code, fieldWidth, padChar);
    }
  }
コード例 #6
0
ファイル: ByteSink.cpp プロジェクト: DaveAckley/MFM
  void ByteSink::Print(s64 decimal, s32 fieldWidth, u8 padChar)
  {
    if (decimal < 0) {
      if (decimal-1 > 0) {
        Print("-9223372036854775808");
        return;
      }
      decimal = -decimal;
      u32 len = CountDigits((u64) decimal, 10) + 1;
      while (fieldWidth > (s32) len) {
        WriteByte(padChar);
        --fieldWidth;
      }
      WriteByte('-');
    }

    Print((u64) decimal, fieldWidth, padChar);
  }
コード例 #7
0
ファイル: checksum.c プロジェクト: Triangled/fossology
/**********************************************
 SumToString(): Compute the checksum, allocate and
 return a string containing the sum value.
 NOTE: The calling function must free() the string!
 Returns NULL on error.
 **********************************************/
char *	SumToString	(Cksum *Sum)
{
  int i;
  char *Result;

  Result = (char *)calloc(1,16*2 +1+ 20*2 +1+ CountDigits(Sum->DataLen) + 1);
  if (!Result) return(NULL);

  for(i=0; i<20; i++)
    {
    sprintf(Result + (i*2),"%02X",Sum->SHA1digest[i]);
    }
  Result[40]='.';
  for(i=0; i<16; i++)
    {
    sprintf(Result + 41 + (i*2),"%02X",Sum->MD5digest[i]);
    }
  Result[41+32]='.';
  sprintf(Result + 33 + 41,"%Lu",(long long unsigned int)Sum->DataLen);
  return(Result);
} /* SumToString() */
コード例 #8
0
ファイル: block.cpp プロジェクト: AndreGleichner/coreclr
unsigned            BasicBlock::dspCheapPreds()
{
    unsigned count = 0;
    for (BasicBlockList* pred = bbCheapPreds; pred != nullptr; pred = pred->next)
    {
        if (count != 0)
        {
            printf(",");
            count += 1;
        }
        printf("BB%02u", pred->block->bbNum);
        count += 4;

        // Account for %02u only handling 2 digits, but we can display more than that.
        unsigned digits = CountDigits(pred->block->bbNum);
        if (digits > 2)
        {
            count += digits - 2;
        }
    }
    return count;
}
コード例 #9
0
ファイル: ByteSink.cpp プロジェクト: DaveAckley/MFM
  void ByteSink::Print(u64 num, Format::Type code, s32 fieldWidth, u8 padChar)
  {

    switch (code) {

    case Format::LXX64:
    case Format::LEX64: {
      u32 base = 10;
      if (code==Format::LXX64)
        base = 16;

      u32 digits = CountDigits(num, base);
      if (fieldWidth > (s32) digits)
        digits = fieldWidth;

      PrintLexDigits(digits);
      PrintInBase(num, (Format::Type) base, fieldWidth, padChar);
      break;
    }

    case Format::BEU64:
    case Format::BEU32:
      WriteByte((num>>(24+32))&0xff);
      WriteByte((num>>(16+32))&0xff);
      WriteByte((num>>( 8+32))&0xff);
      WriteByte((num>>( 0+32))&0xff);

      WriteByte((num>>(24+ 0))&0xff);
      WriteByte((num>>(16+ 0))&0xff);
      WriteByte((num>>( 8+ 0))&0xff);
      WriteByte((num>>( 0+ 0))&0xff);
      break;

    default:
      PrintInBase(num, code, fieldWidth, padChar);
      break;
    }
  }
コード例 #10
0
int main( void )

{
	while (1)
		{
			
			printf("Please input a maximum number to search for primes with: ");
			scanf("%d", &maxNum);
			if ( maxNum >= 2 && maxNum <= 50000)
				break;
			else printf("Incorrect input. Please try again.\n");
				
		}

	
	for (i = 0; i <= maxNum - 1; i++)
	{
		listA[i] = startNum;
		startNum = startNum + 1;
	}
	
	listB[0] = 2;
	for (i = 1; i<=maxNum; i ++)
	{
		for (z = 0; z <= (maxNum - 1)^(1/2); z++)
				{
					listA[e] = 0;
					z = z + (a - 1);
					e = e + a;
				}
		while (1)
			{
				a = listA[f];
				if (a != 0) 
					break;
				else f = f + 1;
						
			}
		if (a <= maxNum) 
			{
				listB[d] = a;
				d++;
				g++;
				e = f;
			}
		else break;	
	}
	
	
	g = maxNum -1;
	while (1)
			{
				if (listB[g] == 0)
				g = g - 1;
				else break;
			}	
	for (i = 0; i <= maxNum; i++)
		{			
			
			if ((i)%8 == 0){
				printf("\n");}
			else if (listB[g] <= maxNum && listB[g] != 0){
				printf("%10d", listB[g]);
				g--;}
				else break;					
		}
	printf("\n\n\nPALINDROMES:\n");	
	g = maxNum - 1;
	i = 1;
	while (1)
	{
			while (1)
				{
					z = listB[g];
					if (z >= 2) 
					break;
					else g = g - 1;
						
				}
			j = CountDigits (z);
			switch (j)
				{
				case 1:	printf("%10d", z); 
						if (i%7 == 0){
							printf("\n");}
						i++;
						break;				
				case 2: digOne = z/10;
						digTwo = z%10;
						digOne = digOne - digTwo;
						if (digOne == 0){
						printf("%10d", z);
						if (i%7 == 0){
							printf("\n");}
						i++;
						}
						else break;
				case 3: digOne = z/100;
						digTwo = z%10;
						digOne = digOne - digTwo;
						if (digOne == 0){
						printf("%10d", z);
						if (i%7 == 0){
							printf("\n");}
						i++;
						}
						else break;
				}
			
			/*if (i%7 == 0)
				printf("\n");*/
			g--;
			if (g < 0)
				break;
			
		}	


	printf("\n\nWHAT NOW????");
return 0;
}
コード例 #11
0
void SequenceInstanceNumeric::Initialize(const SequenceDictionary &dictionary,
                                         SequenceInstance* instance) {
  TokenDictionary *token_dictionary = dictionary.GetTokenDictionary();
  int length = instance->size();
  int i;
  int id;

  int prefix_length = FLAGS_prefix_length;
  int suffix_length = FLAGS_suffix_length;
  bool form_case_sensitive = FLAGS_form_case_sensitive;

  Clear();

  form_ids_.resize(length);
  prefix_ids_.resize(length);
  suffix_ids_.resize(length);
  shape_ids_.resize(length);
  has_digit_.resize(length);
  has_upper_.resize(length);
  has_hyphen_.resize(length);
  all_digits_.resize(length);
  all_digits_with_punctuation_.resize(length);
  all_upper_.resize(length);
  first_upper_.resize(length);
  tag_ids_.resize(length);

  for (i = 0; i < length; i++) {
    std::string form = instance->GetForm(i);
    if (!form_case_sensitive) {
      transform(form.begin(), form.end(), form.begin(), ::tolower);
    }
    id = token_dictionary->GetFormId(form);
    CHECK_LT(id, 0xffff);
    if (id < 0) id = TOKEN_UNKNOWN;
    form_ids_[i] = id;

    prefix_ids_[i].resize(prefix_length);
    for (int l = 0; l < prefix_length; ++l) {
      std::string prefix = form.substr(0, l + 1);
      id = token_dictionary->GetPrefixId(prefix);
      CHECK_LT(id, 0xffff);
      if (id < 0) id = TOKEN_UNKNOWN;
      prefix_ids_[i][l] = id;
    }

    suffix_ids_[i].resize(suffix_length);
    for (int l = 0; l < suffix_length; ++l) {
      int start = form.length() - l - 1;
      if (start < 0) start = 0;
      std::string suffix = form.substr(start, l + 1);
      id = token_dictionary->GetSuffixId(suffix);
      CHECK_LT(id, 0xffff);
      if (id < 0) id = TOKEN_UNKNOWN;
      suffix_ids_[i][l] = id;
    }

    // Compute and store the word shape.
    std::string shape;
    dictionary.GetTokenDictionary()->GetWordShape(instance->GetForm(i), &shape);
    int shape_id = dictionary.GetTokenDictionary()->GetShapeId(shape);
    CHECK_LT(shape_id, 0xffff);
    if (shape_id < 0) shape_id = kUnknownShape;
    shape_ids_[i] = shape_id;

    // Compute and store various flags.
    const char* word = instance->GetForm(i).c_str();
    int word_length = instance->GetForm(i).length();
    int num_digits = CountDigits(word, word_length);

    has_digit_[i] = (num_digits > 0);
    has_upper_[i] = HasUpperCaseLetters(word, word_length);
    has_hyphen_[i] = HasHyphen(word, word_length);
    all_digits_[i] = AllDigits(word, word_length);
    all_digits_with_punctuation_[i] = AllDigitsWithPunctuation(word, word_length);
    all_upper_[i] = AllUpperCase(word, word_length);
    first_upper_[i] = IsCapitalized(word, word_length);

    //id = token_dictionary->GetPosTagId(instance->GetTag(i));
    id = dictionary.GetTagAlphabet().Lookup(instance->GetTag(i));
    //CHECK_LT(id, 0xff);
    //CHECK_GE(id, 0);
    if (id < 0) {
      id = TOKEN_UNKNOWN;
      VLOG(2) << "Unknown tag: " << instance->GetTag(i);
    }
    tag_ids_[i] = id;
  }
}
コード例 #12
0
ファイル: work.c プロジェクト: Falcon77/c_programs
int temp2() 
{
    CountDigits();
}