Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Establecer bits en un número entero y mostrarlo en la página

Estoy tratando de establecer 4 bits en un número entero en función de si una casilla de verificación está marcada. Soy nuevo con JavaScript, así que disculpe mi código incorrecto. Busqué cómo establecer bits y encontré la función setBit . Está claro lo que hace, sin embargo, cuando imprimo el resultado n , sigo obteniendo 0. Estoy seguro de que estoy haciendo algo mal, pero no puedo entender qué es.

Cualquier ayuda es bienvenida.

 function setBit(number, bitPosition) { return number |= 1 << bitPosition; } function checkCheckbox() { var one = document.getElementById("one"); var two = document.getElementById("two"); var three = document.getElementById("three"); var four = document.getElementById("four"); var n = 0 if (one.checked == true) { setBit(n, 0) } if (two.checked == true) { setBit(n, 1) } if (three.checked == true) { setBit(n, 2) } if (four.checked == true) { setBit(n, 3) } return document.getElementById("out").innerHTML = n; }
 <h2>Numbers</h2> <br> <p> 1? <input type="checkbox" id="one" value="1"><br> 2? <input type="checkbox" id="two" value="2"><br> 3? <input type="checkbox" id="three" value="3"><br> 4? <input type="checkbox" id="four" value="4"> </p> <br> <br> <button onclick="checkCheckbox()">Submit</button> <br> <h3 style="color:green" id="out"></h3>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!