示例#1
0
文件: ia.c 项目: Ankirama/Epitech
/*
** brief: if we can't find the good position we will try to remove 1 by 1
** the longer line
** @lst: our list
** @my_bin_p: the first 1 in our result (binary)
** @pos: we will set it with the good position
** return: return the nbr
*/
static int	_fill_hole(t_list *lst, int my_bin_p, int *pos)
{
  int		nbr_tmp;
  int		nbr;
  t_list	*tmp;

  tmp = lst->next;
  *pos = 1;
  while (tmp != NULL && !tmp->bin[my_bin_p])
    {
      (*pos) = (*pos) + 1;
      tmp = tmp->next;
    }
  nbr_tmp = tmp->nbr_ele;
  while (bin_to_int(lst->bin) != 0 && tmp->nbr_ele > 0)
    {
      tmp->nbr_ele -= 1;
      free(tmp->bin);
      tmp->bin = int_to_bin(tmp->nbr_ele);
      free(lst->bin);
      lst->bin = operation_xor(lst);
    }
  nbr = (tmp->nbr_ele == 0) ? 1 : nbr_tmp - tmp->nbr_ele;
  tmp->nbr_ele = nbr_tmp;
  free(tmp->bin);
  tmp->bin = int_to_bin(tmp->nbr_ele);
  return (nbr);
}
示例#2
0
文件: ia.c 项目: Ankirama/Epitech
/*
** brief: it will search the good line to stay with the good strategy
** @lst: our list
** @nbr: our number (we will set it in this function)
** return: return the position found
*/
static int	_find_position(t_list *lst, int *nbr)
{
  int		i;
  int		find;
  int		pos;
  t_list	*tmp;

  *nbr = bin_to_int(lst->bin);
  *nbr = *nbr == 0 ? 1 : *nbr;
  tmp = lst->next;
  i = -1;
  while (++i < ID_OCTET && !lst->bin[i]);
  if (i == 8)
    return (1);
  find = 0;
  pos = 0;
  while (tmp != NULL && !find)
    {
      ++pos;
      find = same_binary(lst, tmp, i - 1);
      tmp = tmp->next;
    }
  if (!find)
    *nbr = _fill_hole(lst, i, &pos);
  return (pos);
}
示例#3
0
文件: func.c 项目: shou-zheng/c
void	func_15_1(void){
	char	*pbin = "01001001";	
	printf("%s(binary)=%d(int) \n",pbin,bin_to_int(pbin));
}