c – Portabilidade independente da endianness na cópia entre valores de bytes[4] para int e float usando memcpy

No windows é de meu conhecimento que um int é escrito na memória em little-endian
Isso significa que se eu escrever um int 450 no endereço apontado por offset é equivalente a:

unsigned char offset2(4); 
offset2(0) = 194; offset2(1)=1; offset2(2)=0; offset2(3)=0;

Porém, se o sistema operacional fosse big-endian, esse seria o código equivalente

unsigned char offset2(4); 
offset2(0) = 0; offset2(1)=0; offset2(2)=1; offset2(3)=194;

Existe alguma maneira melhor de contornar isso para que o código funcione em ambos os casos usando memcpy?

A possível solução usando shift é boa, porém, há problemas quando usada com float ou double

python – TypeError: int() argument must be a string, a bytes-like object or a number, not ‘_io.TextIOWrapper’

Every time when i run this code i get this error:
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘_io.TextIOWrapper’

I want to read some numbers from a file and then gather those numbers with user input.

newBalance = input("What amount of money you want to deposit?")
newBalance = int(newBalance)
balCalcAddRead = open("/home/zewutz/Documents/Learn/python/calculation/balance.txt", "r")
balCalcAdd = int(balCalcAddRead) + int(newBalance)
balCalcAddWrite = open("/home/zewutz/Documents/Learn/python/calculation/balance.txt", "w")
print("Your balance is updated")

I’m new to python and programming.

real analysis – Evaluating $int _0^1frac{ln left(x^2+x+1right)}{xleft(x+1right)}:dx$

How can i evaluate this integral, maybe differentiation under the integral sign? i started expressing the integral as the following,
$$int _0^1frac{ln left(x^2+x+1right)}{xleft(x+1right)}:dx=int _0^1frac{ln left(x^2+x+1right)}{x}:dx-int _0^1frac{ln left(x^2+x+1right)}{x+1}:dx:$$
But i dont know how to keep going, ill appreciate any solutions or hints.

calculus and analysis – solve $int x^{-c} left( 1 + y(x)^2 right)^{-frac{a+1}{2}} dy$ where $e^y = x^c + bx$

I am trying to make some progress on solving the following integral:
$$int_{-infty}^{infty} x^{-c} left( 1 + y(x)^2 right)^{-frac{a+1}{2}} dy$$
with $y(x)$ defined as
$$e^y = x^c + bx$$
for $a in mathbb{N}$, $b in mathbb{R}_+$, $c in mathbb{R}_+$.

In the interesting parameter values (low $a$ and $c$), the integral seems to diverge to $+infty$ at the left and sometimes also at the right tail. If the standard Riemann integral can not be taken, I wonder if there is other way of assigning some reasonable value to it.

My attempts so far:

  1. I considered taking Cauchy Principal Value (https://en.wikipedia.org/wiki/Cauchy_principal_value), but as far as I understand it’s not applicable to tail infinities of the same sign.

  2. I considered methods of contour integration (https://en.wikipedia.org/wiki/Contour_integration), but am not really familiar with them and not sure if they can help here.

  3. I was also thinking about multiplying the function by some special integrator $psi_lambda(x)$ where $lambda$ is some parameter, which would allow taking the integral analytically, and then $lambda$ could be sent to some limiting value forcing it to vanish from the integral’s computed value. But so far I could not come up with the multiplier that works.

  4. Integrating or taking CPV numerically in Mathematica did not help:

In(22):= f1(x) := (x^(-c))*(c*x^(c - 1) + b)/(x^c + b*x);
f2(x) := (1 + (Log(x^c + b*x))^2)^(-(a + 1)/2);
Integrate(f1(x)*f2(x), {x, 0, Infinity}, PrincipalValue -> True, 
 Assumptions -> c > 1 && b > 0 && a >= 1)
a := 1
b := 0.01
c := 2
NIntegrate(f1(x)*f2(x), {c, 0, Infinity})

Out(24)= (x^(-2 c) (b + c x^(-1 + c))^2)/(b x + x^c)^2

Out(25)= Integrate((
 x^-c (b + c x^(-1 + c)))/((b x + x^c) (1 + Log(b x + x^c)^2)), {x, 
  0, (Infinity)}, PrincipalValue -> True, 
 Assumptions -> c > 1 && b > 0)

During evaluation of In(22):= NIntegrate::inumr: The integrand (x^-c (0.01 +c x^(-1+c)))/((0.01 x+x^c) (1+Log(0.01 x+x^c)^2)) has evaluated to non-numerical values for all sampling points in the region with boundaries {{(Infinity),0.}}.

Out(29)= NIntegrate(f1(x) f2(x), {c, 0, (Infinity)})

I would appreciate all the suggestions, negative results with explanations would also help.

An alternative way to write down this integral is substituting out $y$ (with the corresponding correction term):
$$int_{-infty}^{infty} x^{-c} frac{cx^{c-1}+b}{x^c+bx} left( 1 + (ln(x^c+bx))^2 right)^{-frac{a+1}{2}} dx$$

P.S. I have posted earlier a formulation of this question without Mathematica implementation details at https://math.stackexchange.com/questions/3732709/solve-int-x-c-left-1-yx2-right-fraca12-dy-where-ey-x

search problem – Find the location of the smallest int in an unsorted array given a subroutine which provides lower & upper bound on the smallest int from a set

Given an unsorted array $A$ of integers of size $n$, the task is to output the position of the smallest element. Without any additional information, any algorithm for this problem would have a worst-case sample complexity of $n$. However, we have a black box subroutine $S$, which takes as input a set of integers and outputs a lower bound and an upper bound on the smallest integer from that set. Is it then possible to achieve a better sample complexity than $n$?

If we had access to a subroutine $S^*$ which outputs exactly the smallest integer given a set of numbers, then the given problem could have been solved in $log(n)$ samples in the worst case. However, we only have a subroutine which which provides a lower and an upper bound on the smallest integer.

calculus – Evaluate the double integral $int int_{Q} f(x,y)dxdy$

let $f$ be defined on the rectangle $Q =(0,1) times (0,1)$ as follows
$$f(x,y) = begin{cases} 1 text{if} x=y \0 text{ if } x neq y end{cases}$$

Evaluate the double integral $int int_{Q} f(x,y)dxdy$

My attempt : First integrate with respect to $x$

$int_{0}^{1} int_{0}^{1} f(x,y)dxdy=int_{0}^{1}1 dy=1 $

is its True ?

Como ler cada numero de uma variável int e armazenar em uma posição diferente de um array em Java?

Obrigado por contribuir com o Stack Overflow em Português!

  • Certifique-se de responder à pergunta. Entre em detalhes sobre a sua solução e compartilhe o que você descobriu.

Mas evite

  • Pedir esclarecimentos ou detalhes sobre outras respostas.
  • Fazer afirmações baseadas apenas na sua opinião; aponte referências ou experiências anteriores.

Para aprender mais, veja nossas dicas sobre como escrever boas respostas.


if (opcao== "IDPRODUTO"):
    resposta = int(input("Digte o ID do produto que deseja pesquisar "))
    while True:
        for i in lista_idProduto_bd:
            if (resposta == i):
                indice: int = lista_idProduto_bd.index(i)
                resposta:bool = True
                print(f"    33(31mO índice do produto digitado é {resposta}33(m")
                print(f"    33(31mProduto: {lista_idProduto_bd(resposta)}33(mn"
                      f"    33(31mRange de temperatura: {tMin()(resposta)}ºC ~ {tMax()(resposta)}ºC33(mn"
                      f"    33(31mData do Check In: {lista_CheckIn_bd(resposta)}33(mn"
                      f"    33(31mData do Check Out: {lista_CheckOut_bd(resposta)}33(m")
        ***if resposta:***
            print("Produto não cadastrado")

python – AttributeError: ‘int’ object has no attribute ‘getKey’

I try to make a simple hashtable in python with linear probing. My hash table is working but I have some problems with my perfomance testing method.

I am just getting an AtrributeError in the follwing code:

This is my performance method:

def performance(lin_prob=True, rand_input=True):
    Prints the average runtime of k insert operations
    for different sizes of key

        lin_prob - whether linear probing or
            double hashing should be used
        rand_input - whether input should be randomized
            or a predefined (worst case) input

    m = 1009  # first prime bigger than 1000

    # repeat for increasing number of keys
    sizes = (math.floor((m * i) / 50) for i in range(1, 50))
    for k in sizes:

        ht = HashTable(m, lin_prob)

        if rand_input:
            inputs = random.sample(range(10 * m + 1), k)
            inputs = (m * i for i in range(k + 1))

        start_time = time.time()
        for key in inputs:

        total_runtime = (time.time() - start_time) * 1000000
        avg_runtime = total_runtime/k  # average time in nano sec

        print("%dt%.2f" % (k, avg_runtime)) 

I am getting the AttributeError: ‘int’ object has no attribute ‘getKey’, which is referencing to this line ht.insert(key)

There is a conflict with my insert method:

 def insert(self, entry):
        Method inserts key into hash table
        according to the hash value of the key.

            key - key to insert


        key = entry.getKey()
        index = self.hash(key)
        count = 0
        if self.table(index) == None or self.table(index).getValue() == "DELETED":
            self.table(index) = entry
            return count + 1
            inserted = False
            step_size = self.hash_method(key)
            while inserted != True:
                index += ste_size
                count += 1
                if index >= self.size:
                    index = index - self.size
                if self.table(index) == None or self.table(index).getValue() == "DELETED":
                    self.table(index) = entry
                    return count

This line key = entry.getKey() is making the error referencing to the line in my performance method.
Is there another way to implement the line in the performance method?
Or how can I avoid this error? I am just a little newbie in programming, please help me.

java – Listas Simplemente Enlazadas – Eliminar elemento duplicado (int)

Estoy intentando eliminar de una lista enlazada los elementos duplicados independientemente de la posición en la que se encuentren en esta. Tengo una lista con n números enteros que se repiten de manera aleatoria en las posiciones de la lista, para ello he realizado un método que elimina los elementos duplicados, debería dejar tan solo los primeros números y los siguientes que se duplican eliminarlos…

Para ello he realizado varios bucles con nodos que recorren esta lista, uno que recorre de uno en uno y otro bucle en el interior de este que es el que recorre la lista entera por cada numero que tiene la lista y dentro de este una condición que prueba si son iguales el el nodo p con el nodo q
y un contador que cuenta cuantas veces se repite el numero, si este se repite mas de una vez, el nodo salta a la siguiente posición saltando este.

Clase Nodo

public class Nodo {

    private int info;
    private Nodo sig;

    public Nodo() {

        this.info = info;
        this.sig = sig;


    public Nodo(int info) {

        this.info = info;
        this.sig = sig;


    public int getInfo() {

        return info;


    public void setInfo(int info) {

        this.info = info;


    public Nodo getSig() {

        return sig;


    public void setSig(Nodo sig) {

        this.sig = sig;



Clase Lista

public class Lista {

    private Nodo com;

    public Lista() {

        this.com = null;


    public Nodo getCom() {

        return com;


    public void setCom(Nodo com) {

        this.com = com;


    public boolean listaVacia() {

        return com == null;


    public void insertarPrincipio(int info) {

        Nodo p = new Nodo();
        com = p;


    public int getSize() {

        Nodo p = com;
        int contador = 0;

        while(p!=null) {


            p = p.getSig();


        return contador;


    public void eliminarDuplicado() {

        Nodo p = com; //Nodo 1
        Nodo q = com;//Nodo 2
        int contador = 0; //Cuenta cuantas veces se repite el numero

        while(p!=null) { // 4,1,3,2,6,5,3,5,1,2,3,8,3,,7,5,6,3,2,4,5

            contador = 0;

                while(q!=null) { // 4,1,3,2,6,5,3,5,1,2,3,8,3,,7,5,6,3,2,4,5

                    if(p.getInfo()==q.getInfo()) {



                    if(contador>1) {

                        q = q.getSig();


                    System.out.print(q.getInfo() + "-->");
                    q = q.getSig();


            p = p.getSig();



    public String toString() {

        String s = "";

        Nodo p = com;

        if(listaVacia()==false) {

            while(p!=null) {

                s = s + p.getInfo() + "-->";

                p = p.getSig();


        }else {

            s = "La lista esta vacia";


        return s;



Clase Main

public class Main {

    public static void main(String() args) {
        // TODO Auto-generated method stub

        Lista l1 = new Lista();





    public static Lista llenar(Lista l1) {

        int numero () = {5,4,2,3,6,5,7,3,8,3,2,1,5,3,5,6,2,3,1,4};

        for(int i=0; i<numero.length; i++) {



        return l1;



Salida esperada –> 4-1-3-2-6-5-8-7
Salida inesperada –> 4-1-3-2-6-5-3-5-1-2-3-8-3-7-5-3-2-5 (Elimina solo el primer elemento del primer bucle)

He mirado vídeos, documentación y no encuentro una posible solución si alguien me pudiera ayudar a entender por que mi salida recorre tan solo el primer elemento y no elimina todos los repetidos…