Coding Challenge #119: Binary to Decimal Conversion

[ad_1]
In this coding challenge, I discuss binary numbers and make an interactive binary to decimal number converter.

🎥 Next Video:
🔗

💻

🔗 Ternary Operator:

🎥 Seven-Segment Display:

🚂 Website:
💖 Patreon:
Store:
📚 Books:

🎥 Coding Challenges:

🔗 p5.js:
🔗 Processing:


Posted

in

by

Tags:

Comments

41 responses to “Coding Challenge #119: Binary to Decimal Conversion”

  1. Kaixo Avatar

    Is there an easy way to convert binary to decimal using logic gates? I tried googling it but everyone just seems to use a lookup table…

  2. Niklas Koskinen Avatar

    I think the title is a bit misleading. What you're doing here is most certainly not converting binary to decimal but rather only parsing binary strings to integers (which are still binary). The conversion only happens when the result is automaticlly converted to a decimal string for rendering. I was expecting a conversion from integer to binary coded decimal since that would've been more appropriate when working seven segment displays.

  3. as k Avatar

    The 'statement ? true : false' is so simple, i dont get why is it making you any trouble Mr. Dan… Although i think you would be able to easly understand that if you look at this in a proper way, for example like this:
    if you write an if statement, and do someting on the same line, you can easly see how the '?' statement works:

    if(statement) a = 1;
    else a = 2;

    is the same as

    statement ? 1 : 2;

    Result will be the same. Also you can actually combine those, and do someting like that:

    b > 5 ? a = 1 : (b < 3 ? a = 2 : a = 3);

  4. Lee Avatar

    Ayy I watched this live, twas fun.

  5. alexsander gutierreez Avatar

    Hello, I love your videos, I could make a video of raycast implementation in pure javascript.

  6. ChΓ‘vez RaΓΊl Avatar

    Guys, I love this channel, I respect and admire Daniel Shiffman and my passion is programming. I really hate to have to do this and is not my intention to do spam, but I really need help with a processing issue.
    When I try to add a library, a mode or a tool, I can't and a pink error windows message shows saying "Could not connect to the processing server". I've been looking for a solution to that problem, unsuccessfully. I hope to find an answer in this fabulous community, I'd really appreciate it. Thank you!

  7. David Bale Avatar

    8 bits = 1 byte. 4 bits = 1 nybble, 2 bits = $.25

  8. Victor Kohler Avatar

    please do things in processing again

  9. MelonGoggles Avatar

    Honestly. My teacher taught me about binary, decimal and hexadecimal at school. But it was really boring to sit through. I got it in the end but after watching this video i wish my teacher was like you. I mean, lets be honest. This is a pretty boring subject to talk about… but you still somehow manage to make it into a fun and pleasing to watch video while also teaching people about this stuff. Thank you dan!

  10. Noel Diaz Avatar

    you should have a section in your website, where people can submit or link there p5 code, it will be cool to see what people do with this type of challenges

  11. Nerve Clasp Avatar

    I get that this is for those, who only start learning JS, but wouldn't it be cool to introduce some of the ES6 syntax gradually? Otherwise we'll have a lot of new people, who speak Latin =)
    Here's my quick take on the function that would convert binary to decimal:
    `const binaryToDecimal = binaryString => binaryString.split('').reverse().reduce((sum, char, i) => sum + Math.pow(2, parseInt(char)), 0)`

  12. JustGame Avatar

    You can tell most of the programmers who watch you work with high level/abstract programming languages, bitwise operations are used all the time in C and C++, especially if your working with hardware and communicating with individual registers/memory locations

  13. Rage Avatar

    I was really waiting for the ternary operator πŸ™‚

  14. zyad Ayad Avatar

    Can you make half life 3 using any coding language ?

  15. Hasan Cakir Avatar

    coding challenge 119: back to the cs101 πŸ™‚

  16. Gabriel Avatar

    Love your channel πŸ˜€ i work as a dev and from time to time we have kids, interested in computer science, at work. And I love using p5js and your fun ideas to give them a first insight into coding. Obviously i also recommend your channel to them πŸ˜‰

  17. Winter Gupta Avatar

    Successfully completed it :D, thank you for the idea.

  18. S K Avatar

    I love this channel and this videos! It's soooo helpful, thank you very much! Don't ever stop making these vids!

  19. Izumi Koushiro Avatar

    There's probably a hundred easier ways but this is what I scratched out anway.

    function bin_to_dec(binary) {
    if (binary.match(/[^0-1]/)) return undefined;

    return binary.split("").reverse().map(Number)
    .reduce((dec, bit, index) => dec += Math.pow(2, index) * bit, 0);
    }

  20. Josh Brown Avatar

    this.state = 1 – this.state
    Simple toggle between 1 and 0

  21. GntlmnWzrd Avatar

    Dan I've been watching your playlist on processing, and I just wanted to say I'm a big fan of your videos and teaching style. YOU ARE THE REASON I'm passing my intro to computer science class. I have now become an avid fan of yours, and will continue to promote your videos and content. Keep up being you, you have made learning this stuff for me fun!

  22. Chemielehrer und Philosoph Avatar

    You always frown upon "computer science", but I think, you are a great scientist – and that is meant as a sincere compliment!

  23. gog jjw Avatar

    The bit mask is a very convenient technique when handling a set.

    Let set S as {1, 3, 4, 5, 9}

    You can represent S as 2^1 + 2^3 + 2^4 + 2^5 + 2^9 = 570

    and If you want to..

    check the set S has number β€œn”
    -> S & (1 << n)

    add number β€œn” to set S
    -> S | (1<<n)

    delete number β€œn” of set S
    -> S & ~(1<<n)

  24. Holla Holla Avatar

    you look awesome today

  25. Sita Ram Shrama Chetan Avatar

    Hey can tell me how to code in java a program by which I am able to draw mathematical curves like you equals x square

  26. Shreerang Vaidya Avatar

    I am back to this chann after a year long gap, and it still is so fresh!

  27. Abdullah Qannass Avatar

    Its the sum of each digit times the place. Elemantary.

  28. Dave Messer Avatar

    Another premiere? Another video in my feed I’m less likely to watch.

  29. hirnlager Avatar

    /*hex to dec*/ 0xff/1 // 255

  30. hirnlager Avatar

    parseInt("1000", 2); /* 8 */

  31. paul smith Avatar

    oh great more of this premiere crap getting sick of videos showing up that are not even watchable yet

  32. Onisor Mircea Avatar

    Wow, I had this homework in highschool! :))

  33. DowzerWTP72 Avatar

    #include <math.h>
    #include <string>
    using namespace std;

    string binaryString = "0110010";
    int decimalOut = 0;

    int main() {

    for (int b=0; b<8; b++) {
    if (binaryString[b] == '1') {
    decimalOut += pow(2, b);
    }

    system("cls");
    printf("%s == %d nn", binaryString, decimalOut);
    system("pause");

    return 0;
    }

  34. DowzerWTP72 Avatar

    var binaryString = "1001101";
    var decimalInt = 0;

    for (var b=0; b<binaryString.length; b++) {
    decimalInt += pow(2,b) * (binaryString[b] == '1');
    }

    return decimalInt;

  35. Haha007 Avatar

    Hmmm is this gonna be boring addition or some funky binary to bcd using double dabble? I think that would make a funny challenge. ;p

  36. Anton Funk Avatar

    More and more youtubers find out about this feature

Leave a Reply

Your email address will not be published. Required fields are marked *