Binary to decimal can’t be that hard, right?

preview_player
Показать описание


0:00 Introduction
2:09 Separating digits by dividing by 10
3:24 Dividing numbers in binary by hand
9:26 An algorithm for binary division
19:06 Implementing the algorithm in 6502 assembly
34:14 Running the program
34:45 Reversing the digits
41:38 It works!


------------------

Social media:

Special thanks to these supporters for making this video possible:
Adrien Friggeri, Alexander Wendland, Andrew Vauter, Anson VanDoren, Armin Brauns, Ben Dyson, Ben Kamens, Ben Williams, Bill Cooksey, Binh Tran, Bouke Groenescheij, Bradley Pirtle, Bryan Brickman, Carlos Ambrozak, Christopher Blackmon, Cole Johnson, Daniel Jeppsson, Daniel Sackett, Daniel Tang, Dave Burley, Dave Walter, David Brown, David Clark, David House, David Sastre Medina, David Turnbull, David Turner, Dean Winger, Dmitry Guyvoronsky, Dušan Dželebdžić, Dzevad Trumic, Emilio Mendoza, Eric Brummer, Eric Busalacchi, Eric Dynowski, Eric Twilegar, Erik Broeders, Eugene Bulkin, fxshlein, George Miroshnykov, Harry McDow, HaykH, Hidde de Jong, Ian Tait, Ingo Eble, Ivan Sorokin, Jason DeStefano, Jason Specland, JavaXP, Jay Binks, Jayne Gabriele, Jeremy A., Jeremy Wise, Joe OConnor, Joe Pregracke, Joel Jakobsson, Joel Messerli, Joel Miller, Johannes Lundberg, John Fenwick, John Meade, Jon Dugan, Joshua King, Kefen, Kenneth Christensen, Kent Collins, Koreo, Lambda GPU Workstations, Larry, London Dobbs, Lucas Nestor, Lukasz Pacholik, Maksym Zavershynskyi, Marcus Classon, Martin Roth, Mats Fredriksson, Matt Alexander, Matthäus Pawelczyk, melvin2001, Michael Burke, Michael Garland, Michael Tedder, Michael Timbrook, Miguel Ríos, Mikel Lindsaar, Nicholas Moresco, Örn Arnarson, Örper Forilan, Paul Pluzhnikov, Paul Randal, Pete Dietl, Philip Hofstetter, Randy True, Ric King, Richard Wells, Rob Bruno, Robert Diaz, Ron Maxwell, sam raza, Sam Rose, Sergey Ten, SonOfSofaman, Stefan Nesinger, Stefanus Du Toit, Stephen Kelley, Stephen Riley, Stephen Smithstone, Steve Jones, Steve Gorman, Steven Pequeno, TheWebMachine, Tom Burns, Vlad Goran, Vladimir Kanazir, Warren Miller, xisente, Yusuke Saito
Рекомендации по теме
Комментарии
Автор

Kudos to every programmer who solved these problems in assembly long before I started programming.

ChrisB...
Автор

I started out on the 6502 almost 40 years ago. Beyond the nostalgia, it’s great to see, in the comments here, new generations experience the joy and wonder as I did so many years ago. Awesome job, Ben.

Hacker-at-Large
Автор

“I was able to print that out pretty easily - well, it took 9 videos” - and this is why we love this channel

andrewjvaughan
Автор

"Binary to decimal can't be that hard, right?" *sees video is 42 minutes long*

spychicken
Автор

Man, I've been struggling how to do that without Decimal Mode for months. I'm working on a calculator program on the NES and have been running into that program again and again. Every time I looked up how to do it on 6502, they always said "Use Decimal Mode". But the NES's 2A03 doesn't have a decimal mode!

I could hug you!

EvilSandwich
Автор

8:20 - When you keep leveling up your computer engineering skills, eventually you get the power to infinitely unfold paper with the next calculations already written on it. :)

skaruts
Автор

9:00 you didn’t do the math wrong, a bit just got flipped while transmitting.

MinecraftTestSquad
Автор

this is the only guy that would make a whole iOS app just to solve an assembly problem

MrLjupcekolev
Автор

This is gonna be a good one, I can tell. Glad you're back!

micahgilbertcubing
Автор

More complex ISA that actually have a div instruction _still_ do this algortihm underneath automatically in hardware. That's why if you check the datasheet for them, the div instruction takes ~16x cycles to complete than a normal instruction (for the appropriate word size)

tiger
Автор

"So we're going to do this rotate left, right?"

It's like talking to my dad

"So we go left, right?"
"Wait, left, then right?"
"No, left, right?"
"Right?"
"No, left"
"Left?"
"Right!"

🤯

AntneeUK
Автор

Can;t wait for the floating point number arithmetics series!

firwlkr
Автор

The joy I'm feeling being able to witness a demonstration of how a computer does math at the machine level is indescribable! (At least somewhere between machine level and assembly ;p ) I am a visual learner who once seeing a demonstration can picture what a written document is describing. Sort of like needing a Rosetta Stone to understand the syntax of a text. This video series has welcomed me back to an electronics hobby I abandoned some 25 years ago as a teen. Thank you for posting these!

jc-h
Автор

I think for me the hard part of binary maths is the cascading carry or borrow.

The rotating of the number automatically pushing the answer into the "memory" spot was elegant as fuck. Nice.

K-o-R
Автор

Instead of reversing the string with code so it appears "correctly" ordered in RAM, why not just write the values into RAM as you go, and use the Y register to count how many results you get. Then when you're done, just decrement trough the Y index and print each character, thereby removing the need for a code to iterate trough the string to insert a character. Just a suggestion.

arsenic
Автор

I have a degree in IT so I have a pretty good understanding of how to USE computers and some of the basics on how they work, but this channel is awesome because it really makes the ultra low-level stuff click to explain how they work on a physical level. Never ceases to fascinate me, I really appreciate the effort that goes into sharing this stuff.

codythomashunsberger
Автор

Using Ramanujan's number... I see...

gz
Автор

There's a much easier way to convert binary numbers to decimal on the 6502. Essentially, you left-shift the value out of the input 16-bit word (MSB→LSB) and left-shift the carry flag from that into the output 16-bit word. Mathematically, this just copies the value bit-by-bit from one word to another. Except that instead of using ROL:ROL to rotate the bit into the output word, you ADC the value in the output word to itself plus the carry from the first word, and instead of doing a normal binary addition, you do a Decimal-Mode addition (SED). The result will be in Binary Coded Decimal instead of binary, which is easy to convert into ASCII, and the output word will need to be three bytes in size to hold results over 9999.

csbruce
Автор

Ben, where were you back in 1982 when I was learning about binary math. This is some very elegant coding and apart form the print routine there is not one sign of a nasty little jmp instruction, everything is relative calls using bne or beq. You explanation of the math is very clear and my past teachers could learn a lot from your presentation style. Thanks for producing this video, I am sure that a lot of viewers who need to learn the concepts of binary math will benefit greatly from this video ;)

boredwithusernames
Автор

Very good video! You have no idea how good you explain stuff. I have literally never seen anything related to assembly other than the fact that its a very low level machine language and I was able to follow along!

The visual representation of the algorithm was excellent. It shows that you really have a passion for teaching which I wholefully appreciate as a comsci student!

Thank you for making this. I will definitely look into your other stuff :D

acex
join shbcf.ru