At my school, they taught us decimal to binary conversion like this (and it would solve your "constraint" to 8 bits): I'm going to show you an example what the procedure is: Let's say we want to convert 90: 90 / 2 = 45 Remainder 0 45 / 2 = 22 Remainder 1 22 / 2 = 11 Remainder 0 11 / 2 = 5 Remainder 1 5 / 2 = 2 Remainder 1 2 / 2 = 1 Remainder 0 1 / 2 = 0 Remainder 1 Now read the remainders from bottom to the top, and you'll get the binary number from left to right: 1011010 And you could then code your converting algorithm so that it divides by two and saves the remainder until the number that is getting divided reaches 0
@kirkanos7716 жыл бұрын
or you can type (90 >>> 0).toString(2) that is way more faster than the cyclomatically complex algorithm you are trying to use. It was fun in the 90s when you had to optimize computation for your game to run smoothly on a i386. But nowadays, the native methods are going to be faster, anytime.
@sigmareaver6806 жыл бұрын
That's cool. So it'd be something like this psuedo code: x = 90, n[] while (x) n.insert(0, x % 2) x = x / 2 end
@polskus6 жыл бұрын
@@kirkanos771 Yes, Daniel even mentioned that he could just use num.toString(2), but he wanted to show the conversion from decimal to binary. What I don't understand in your proposed code though is why you want to logically shift right by zero and then convert to binary.
@polskus6 жыл бұрын
@@sigmareaver680 Yes, and then reverse the Array and you got the numbers in the correct order.
@kirkanos7716 жыл бұрын
IceCreeper28 You can ignore the triple shift operator, it is just there to prevent shifting negative numbers. That could give undesirable effects. It's up to you to use it if you intend to manage the binary representation of negative numbers (it's band dependant though, 32 bits ? yep, i just tried in the console).
@Remls6 жыл бұрын
4:52 "Function ..." **writes something not even remotely resembling the word function**
@benstoffels51086 жыл бұрын
Haha
@Engineer97366 жыл бұрын
Tijmf6 😂
@jamessantiago22536 жыл бұрын
I always type funciton! Function seems to be a difficult word to type! Maybe this is why in javascript we now have arrow functions!
You are SO the perfect nerd. Loving your uploads! Thanks!
@wowatomica6 жыл бұрын
Dude Dan the happiest shiftman.. your excitement is so contagious!
@mayursaroj43606 жыл бұрын
he is so passionate about what he does..i want to be like him..😊😍
@picosdrivethru2 жыл бұрын
I know right! It's infectious, I love it.
@AfonsodelCB6 жыл бұрын
I was gonna learn this some time in school in the new few months, but I'm glad you explained this before it happen, will make life a lot easier. your explanations are also better than that of most teachers
@GuitarreroDaniel4 жыл бұрын
I love your energy man, great explanation btw
@nick119276 жыл бұрын
I was going to make a "clever" joke about Shiftman but you made it for me :(
@mmahgoub6 жыл бұрын
We love you, Daniel!
@shervilgupta926 жыл бұрын
Ive added both kinda shifts by number of bits user specifies. :D , man you really have developed my interest in coding again...
@WildAnimalChannel6 жыл бұрын
Mr SHIFTman you did some good bit of bit SHIFTing on this SHIFT.
@BitShifting-h3qАй бұрын
bit-shifting is the best thing that ever happened to me
@OrangeC76 жыл бұрын
"tijmf6 shiftBits() { }" Has a nice ring to it.
@998joko6 жыл бұрын
please do challenge in Line algorithm like bresenhams line, midpoint line etc. i love your entire video...
@DogwafflDan6 жыл бұрын
Like it when you cover the old school tricks!
@kamoroso946 жыл бұрын
Oh Dan, you could look at showing how bit flags work with masking in your next video! Also, if you wanna take this idea to the extreme to really solidify the idea of bit shifting and masking, you could implement a bitmap. Every bit would be like an element in a Boolean array, just stored more compactly as bits.
@gregcampbell44676 жыл бұрын
10:52 "Is it weird how much fun this is for me?" Dunno, Is it weird how much I enjoy watching you have fun in front of a video camera in a closet?
@MrRushifyIt6 жыл бұрын
You got so excited at 13:35 :D you're great
@georgeyjm6 жыл бұрын
5:44 I always do this when I'm explaining something to someone...And they just have no idea what I'm "oh"ing and "ah"ing about.
@nielsdaemen2 жыл бұрын
I had no idea JavaScript supported bitwise operators just like C Interesting video as always 😁
@eugenetswong2 жыл бұрын
Thank you for this and #119. I hope to get good at programming. I figure that bit operations are important.
@DominicVictoria6 жыл бұрын
Just like shifting a base 10 number(Regular numbers we use as humans) either multiplies it or divides it by 10
@Softwareengineeringdev6 жыл бұрын
Well Explained !
@andremonteiro34086 жыл бұрын
Hey, could you make a coding challenge for a pool game ? It would be cool :D
@willysatrionugroho80865 жыл бұрын
Yup it's interesting because binary is 2 number system while decimal is 10 number system. If you want to get hundreds from thousands just divide it by 10. Same concept applies in any number system, in binary divide it by two, in nonal divide it by 9,in hexadecimal divide it by 16, and so on.
@TelosZeratul6 жыл бұрын
Oh, okay. I forgot about you, the viewer! Auhauhauhaaua. (Daniel getting into the his own world of craziness and creativity)
@LaurensVRC6 жыл бұрын
New coding challenge: two swirling galaxies colliding... :D
@RicoGalassi6 жыл бұрын
do you think it would be hard to do a coding challenge without talking? hahah Love your videos btw! It's nice to hear you think everything out!
@alexfrasca6736 жыл бұрын
Hi dan, a bit of visual design advice.. if you want something to appear "on" or "off," you must make the background the darkest (or lightest) color. Otherwise, on and off will be perceived as a similar contrast from the background, so for the viewer it's just kind of confusing. So maybe make the background 51, "off" 100, and "on" 255
@TheCodingTrain6 жыл бұрын
Thank you!!
@Ofilafoo6 жыл бұрын
You make me love Rainbows. Thanks that you beeing here
@sebguex19706 жыл бұрын
An easier to convert a number from decimal to binary is to see whether the given number can be divided by 2. If it is then the least significant bit (the one that correspond to the power of 0) will be 0, and if it isn't this bit is going to be 1. Then you just have to take you number and divide it by 2 and repeat the process (as dividing by 2 just shifts the bits to the right by 1 place) until you end up with a value of zero. Then you just fill the higher powers with 0 The algorithm (pseudocode) would be : Create an empty string Create a copy of your number which I'll call val For i between 0 (included) and 8 (excluded) { If val % 2 == 1 then add 1 to the front of the string, otherwise add 0 val = val/2 If val == 0 then fill the string with zeros from the front until its size is 8 and break from the loop. } Return the string
@pheisar6 жыл бұрын
5:42 Love it!
@sigmareaver6806 жыл бұрын
Is it possible to request a topic be covered? If so, I'd really like help with concave polygon triangulation and collision detection. I haven't found good explanations online.
You could have put the updating of the byte array right into the decimalToBinary for loop. Would have saved CPU cycles. This would of course require a rename of the decimalToBinary function. Maybe decimalToByteArray or so.
@minebastiii6 жыл бұрын
So you are Daniel Shiftman? :D Now I watched the video ^^
@avi126 жыл бұрын
12:48 My eyes are burning for not using "%=" operator!
@alfredomant6 жыл бұрын
avi12 Oh look! the next Mark Zuckerberg 😂
@pidi646 жыл бұрын
function DecToBinStr(value) { if(!value) return "0"; let output = ""; while(value > 0) { output = (value & 1) + output; value >>= 1; } return output; }
@zyada93346 жыл бұрын
Can you make half life 3 using any coding language ?
@Engineer97366 жыл бұрын
lazlo the boy It was a joke. Since the world is already waiting for HL3 since 2004. It has some kind of legendary status.
@k.alipardhan69576 жыл бұрын
@@thebirdhasbeencharged opengl sucks :P
@shocelot34826 жыл бұрын
Subbed!!
@edoardomagenta69176 жыл бұрын
Maybe, in the next codding challenge, you can try to rappresents atomic orbital shape using functions
@TwistedSoul20024 жыл бұрын
I wanted to like this video- you seem very knowledgeable and can definitely explain things well.... the problem I found is that the presentation was a bit ‘scatter brain’. The explanation jumps around too much and you reference things we don’t know about.. I’m already confused about *why* we need to binary shift but I only made it to 06:34 before I bailed. This would be good as a first take...
@proki80816 жыл бұрын
Trying to learn to code idea where to start
@TheCodingTrain6 жыл бұрын
My beginner playlist (no prior knowledge required) is here: kzbin.info/www/bejne/r4G6nIOFm9N6qdk
@pacibrzank786 жыл бұрын
Why are you using “let“ instead of “var“?
@TheCodingTrain6 жыл бұрын
I talk about let and var in this video: kzbin.info/www/bejne/p2m2eZR6hsmoopI
@voiddeepstorage65335 жыл бұрын
Decimal to binary is easy: int n = 255 char[] byte = new char[8]; int c = 7; while(n!=1){ char[c] = n%2 == 0 ? 1 : 0; n /= 2; c--; } ( I dont know if this works 100%, but i have a code that uses the same logic ( n%2 ) that works fine )
@XoIoRouge6 жыл бұрын
Wait, the next video isn't available? Wait, this video was posted a few days ago? *I caught up?!* :(
@kevinandrews93026 жыл бұрын
you should mess around with hexadecimals while you're on the subject of bitwise stuff!
@anuraghazra47726 жыл бұрын
I have a question actually, how does p5 knows that the p5's native functions are called outside of draw or setup?
@RealSquidicus6 жыл бұрын
Because when p5 is imported the functions are made global, they can be accessed anywhere.
@anuraghazra47726 жыл бұрын
No, i mean when i use any function outside of draw() or setup() p5js gives me - "Did you just try to use p5.js's rect() function? If so, you may want to move it into your sketch's setup() function. " - This Warning Message, but how does p5js knows that i am using it outside of setup() or draw()?
@WannesMalfait6 жыл бұрын
@@anuraghazra4772 you can create your own functions right? Well if you "create" a function that is part of p5 it will first try to treat it as your own function but then see it exists and realise that it should be in setup or draw. That's what I think.
@RealSquidicus6 жыл бұрын
@@anuraghazra4772 my guess would be because technically everything is being called via either the setup or draw, e.g show has rect/ellipse functions but it gets called from draw, maybe you're trying to call these functions in a different way? It'll give you a warning because I believe the draw function is supposed to know what is being drawn and external calls might mess with it
@potatoes81696 жыл бұрын
I dont know how they do it, but a possible way to do: function onload() { //.... //otherstuff here SETTINGUP = true; setup(); SETTINGUP = false; //otherstuff here //.. } function size() { if(SETTINGUP ) { //... } else console.debug("Warning message blah blah blah .."); } Anyway thats just my guess. (I didnt check if thats what they do).
@basilbaby20696 жыл бұрын
💜💜💜
@charlesbinet23016 жыл бұрын
Do it with any base (with a base slider) ;)
@user-zu6ts5fb6g6 жыл бұрын
lol thats so cool!
@MyurrDurr6 жыл бұрын
*tijmf6* Ah yes, my favorite function name
@aminthemar5 жыл бұрын
0:01 Hello! Welcome to coding challenge, BITCH!! Shifting...
@avi126 жыл бұрын
11:26 Or just: 2 ** i
@bapolino7336 жыл бұрын
You should release more videos with a premier before the actual release
@mcfansrandomvids6 жыл бұрын
Seventh!
@patson39104 жыл бұрын
ahaha you're so cool
@neuralengine9656 жыл бұрын
Where is interesting stuff like ml5.js?
@AlgyCuber6 жыл бұрын
first!!!!
@sofi-up4kd6 жыл бұрын
holaaaa
@sonialangemotion6 жыл бұрын
Please make a Voronoi cells coding challenge!!
@lennysmileyface6 жыл бұрын
90 / 128 = 0r90?? What maths are you doing mate?
@Everything_Music2 жыл бұрын
This seems like the mind of someone with ADHD, going all over the place. Good video though :)
@Linxy6 жыл бұрын
RIP now we will have horrible codebases where people bitshift instead of using / and *