コード例 #1
0
char *floattobinfloat(long double value, char *buffer) {
  /* Convert an float value in an binary string stored in the given pointer;
   ************************************************************************/
  if (buffer == NULL) {
    /** Given an NULL pointer as argument **/
    buffer=calloc(128,sizeof(char)) ;
  }
 
  #ifdef HAVE_MALLOC_USABLE_SIZE
 
  if (malloc_usable_size(buffer) < 128)  {
    if ( realloc(buffer,128) == NULL) {
      errno=EINVAL ;	
      return NULL ;
    }
   
  }
 
  #endif
 
  long double int_part=0.0 ;
  long double float_part=0.0 ;
 
  float_part=modfl(value,&int_part) ; /** modulo float */
 
  /** variables for splitting in integer and float part */
  char *int_part_str_bin=malloc(128) ;
  char *float_part_str_bin=malloc(128) ;
  memset(int_part_str_bin,'\0',128) ;
  memset(float_part_str_bin,'\0',128) ;
 
  /** Perform splitting in integer and float part */
  inttobin((long long) int_part,int_part_str_bin) ;
  __inttobinfloatpart(float_part,float_part_str_bin,128) ;
 
  /** result binary string variable (pointer given as argument) */
  memset(buffer,'\0',128) ;
  if ( ( value  < 0) && (int_part_str_bin[0] != '-') ) {
    /** Case value to convert in binfloat string is negativ */
    strcpy(buffer,"-") ;
  }
 
  /** Assemble final binary string */
  strcat(buffer,int_part_str_bin) ;
  strcat(buffer,".") ;
  strcat(buffer,float_part_str_bin) ;
 
  buffer[127]='\0' ;
 
  return buffer ;
 
}
コード例 #2
0
ファイル: main.cpp プロジェクト: gladiopeace/charBin
main(){
int n, count;
//array of small letters
char sletter[27] = "abcdefghijklmnopqrstuvwxyz";
//array of big letters
char bletter[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//check the int value of small letters from a to z
for(count = 0; count<26; count++){
n=sletter[count]; //get int value of a characters
printf("%c = %d = ",sletter[count],n ); //print a character and its integer value
inttobin(n);//calls function to convert integer value to binary and prints it
printf("\n");
}
printf("\nThe Big Letters\n\n");
//check the int value of BIG letters from A to Z
for(count = 0; count<26; count++){
n=bletter[count];//get int value of a characters
printf("%c = %d = ",bletter[count],n );//print a character and its integer value
inttobin(n);//calls function to convert integer value to binary and prints it
printf("\n");
}
getch(); //i don't know, it's my practice so the program won't terminate immediately after running.
return 0;
}