Coding Challenge

  Рет қаралды 44,681

The Coding Train

The Coding Train

Күн бұрын

Пікірлер: 92
@polskus
@polskus 6 жыл бұрын
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
@kirkanos771
@kirkanos771 6 жыл бұрын
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.
@sigmareaver680
@sigmareaver680 6 жыл бұрын
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
@polskus
@polskus 6 жыл бұрын
@@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.
@polskus
@polskus 6 жыл бұрын
@@sigmareaver680 Yes, and then reverse the Array and you got the numbers in the correct order.
@kirkanos771
@kirkanos771 6 жыл бұрын
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).
@Remls
@Remls 6 жыл бұрын
4:52 "Function ..." **writes something not even remotely resembling the word function**
@benstoffels5108
@benstoffels5108 6 жыл бұрын
Haha
@Engineer9736
@Engineer9736 6 жыл бұрын
Tijmf6 😂
@jamessantiago2253
@jamessantiago2253 6 жыл бұрын
I always type funciton! Function seems to be a difficult word to type! Maybe this is why in javascript we now have arrow functions!
@dionzz99
@dionzz99 6 жыл бұрын
"Shift.." "ehi" **backspace intensifies** "ejot" **backspace again**
@thorzweegers7616
@thorzweegers7616 2 жыл бұрын
You are SO the perfect nerd. Loving your uploads! Thanks!
@wowatomica
@wowatomica 6 жыл бұрын
Dude Dan the happiest shiftman.. your excitement is so contagious!
@mayursaroj4360
@mayursaroj4360 6 жыл бұрын
he is so passionate about what he does..i want to be like him..😊😍
@picosdrivethru
@picosdrivethru 2 жыл бұрын
I know right! It's infectious, I love it.
@AfonsodelCB
@AfonsodelCB 6 жыл бұрын
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
@GuitarreroDaniel
@GuitarreroDaniel 4 жыл бұрын
I love your energy man, great explanation btw
@nick11927
@nick11927 6 жыл бұрын
I was going to make a "clever" joke about Shiftman but you made it for me :(
@mmahgoub
@mmahgoub 6 жыл бұрын
We love you, Daniel!
@shervilgupta92
@shervilgupta92 6 жыл бұрын
Ive added both kinda shifts by number of bits user specifies. :D , man you really have developed my interest in coding again...
@WildAnimalChannel
@WildAnimalChannel 6 жыл бұрын
Mr SHIFTman you did some good bit of bit SHIFTing on this SHIFT.
@BitShifting-h3q
@BitShifting-h3q Ай бұрын
bit-shifting is the best thing that ever happened to me
@OrangeC7
@OrangeC7 6 жыл бұрын
"tijmf6 shiftBits() { }" Has a nice ring to it.
@998joko
@998joko 6 жыл бұрын
please do challenge in Line algorithm like bresenhams line, midpoint line etc. i love your entire video...
@DogwafflDan
@DogwafflDan 6 жыл бұрын
Like it when you cover the old school tricks!
@kamoroso94
@kamoroso94 6 жыл бұрын
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.
@gregcampbell4467
@gregcampbell4467 6 жыл бұрын
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?
@MrRushifyIt
@MrRushifyIt 6 жыл бұрын
You got so excited at 13:35 :D you're great
@georgeyjm
@georgeyjm 6 жыл бұрын
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.
@nielsdaemen
@nielsdaemen 2 жыл бұрын
I had no idea JavaScript supported bitwise operators just like C Interesting video as always 😁
@eugenetswong
@eugenetswong 2 жыл бұрын
Thank you for this and #119. I hope to get good at programming. I figure that bit operations are important.
@DominicVictoria
@DominicVictoria 6 жыл бұрын
Just like shifting a base 10 number(Regular numbers we use as humans) either multiplies it or divides it by 10
@Softwareengineeringdev
@Softwareengineeringdev 6 жыл бұрын
Well Explained !
@andremonteiro3408
@andremonteiro3408 6 жыл бұрын
Hey, could you make a coding challenge for a pool game ? It would be cool :D
@willysatrionugroho8086
@willysatrionugroho8086 5 жыл бұрын
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.
@TelosZeratul
@TelosZeratul 6 жыл бұрын
Oh, okay. I forgot about you, the viewer! Auhauhauhaaua. (Daniel getting into the his own world of craziness and creativity)
@LaurensVRC
@LaurensVRC 6 жыл бұрын
New coding challenge: two swirling galaxies colliding... :D
@RicoGalassi
@RicoGalassi 6 жыл бұрын
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!
@alexfrasca673
@alexfrasca673 6 жыл бұрын
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
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Thank you!!
@Ofilafoo
@Ofilafoo 6 жыл бұрын
You make me love Rainbows. Thanks that you beeing here
@sebguex1970
@sebguex1970 6 жыл бұрын
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
@pheisar
@pheisar 6 жыл бұрын
5:42 Love it!
@sigmareaver680
@sigmareaver680 6 жыл бұрын
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.
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues
@Engineer9736
@Engineer9736 6 жыл бұрын
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.
@minebastiii
@minebastiii 6 жыл бұрын
So you are Daniel Shiftman? :D Now I watched the video ^^
@avi12
@avi12 6 жыл бұрын
12:48 My eyes are burning for not using "%=" operator!
@alfredomant
@alfredomant 6 жыл бұрын
avi12 Oh look! the next Mark Zuckerberg 😂
@pidi64
@pidi64 6 жыл бұрын
function DecToBinStr(value) { if(!value) return "0"; let output = ""; while(value > 0) { output = (value & 1) + output; value >>= 1; } return output; }
@zyada9334
@zyada9334 6 жыл бұрын
Can you make half life 3 using any coding language ?
@Engineer9736
@Engineer9736 6 жыл бұрын
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.alipardhan6957
@k.alipardhan6957 6 жыл бұрын
@@thebirdhasbeencharged opengl sucks :P
@shocelot3482
@shocelot3482 6 жыл бұрын
Subbed!!
@edoardomagenta6917
@edoardomagenta6917 6 жыл бұрын
Maybe, in the next codding challenge, you can try to rappresents atomic orbital shape using functions
@TwistedSoul2002
@TwistedSoul2002 4 жыл бұрын
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...
@proki8081
@proki8081 6 жыл бұрын
Trying to learn to code idea where to start
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
My beginner playlist (no prior knowledge required) is here: kzbin.info/www/bejne/r4G6nIOFm9N6qdk
@pacibrzank78
@pacibrzank78 6 жыл бұрын
Why are you using “let“ instead of “var“?
@TheCodingTrain
@TheCodingTrain 6 жыл бұрын
I talk about let and var in this video: kzbin.info/www/bejne/p2m2eZR6hsmoopI
@voiddeepstorage6533
@voiddeepstorage6533 5 жыл бұрын
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 )
@XoIoRouge
@XoIoRouge 6 жыл бұрын
Wait, the next video isn't available? Wait, this video was posted a few days ago? *I caught up?!* :(
@kevinandrews9302
@kevinandrews9302 6 жыл бұрын
you should mess around with hexadecimals while you're on the subject of bitwise stuff!
@anuraghazra4772
@anuraghazra4772 6 жыл бұрын
I have a question actually, how does p5 knows that the p5's native functions are called outside of draw or setup?
@RealSquidicus
@RealSquidicus 6 жыл бұрын
Because when p5 is imported the functions are made global, they can be accessed anywhere.
@anuraghazra4772
@anuraghazra4772 6 жыл бұрын
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()?
@WannesMalfait
@WannesMalfait 6 жыл бұрын
@@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.
@RealSquidicus
@RealSquidicus 6 жыл бұрын
@@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
@potatoes8169
@potatoes8169 6 жыл бұрын
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).
@basilbaby2069
@basilbaby2069 6 жыл бұрын
💜💜💜
@charlesbinet2301
@charlesbinet2301 6 жыл бұрын
Do it with any base (with a base slider) ;)
@user-zu6ts5fb6g
@user-zu6ts5fb6g 6 жыл бұрын
lol thats so cool!
@MyurrDurr
@MyurrDurr 6 жыл бұрын
*tijmf6* Ah yes, my favorite function name
@aminthemar
@aminthemar 5 жыл бұрын
0:01 Hello! Welcome to coding challenge, BITCH!! Shifting...
@avi12
@avi12 6 жыл бұрын
11:26 Or just: 2 ** i
@bapolino733
@bapolino733 6 жыл бұрын
You should release more videos with a premier before the actual release
@mcfansrandomvids
@mcfansrandomvids 6 жыл бұрын
Seventh!
@patson3910
@patson3910 4 жыл бұрын
ahaha you're so cool
@neuralengine965
@neuralengine965 6 жыл бұрын
Where is interesting stuff like ml5.js?
@AlgyCuber
@AlgyCuber 6 жыл бұрын
first!!!!
@sofi-up4kd
@sofi-up4kd 6 жыл бұрын
holaaaa
@sonialangemotion
@sonialangemotion 6 жыл бұрын
Please make a Voronoi cells coding challenge!!
@lennysmileyface
@lennysmileyface 6 жыл бұрын
90 / 128 = 0r90?? What maths are you doing mate?
@Everything_Music
@Everything_Music 2 жыл бұрын
This seems like the mind of someone with ADHD, going all over the place. Good video though :)
@Linxy
@Linxy 6 жыл бұрын
RIP now we will have horrible codebases where people bitshift instead of using / and *
@Flor12344
@Flor12344 6 жыл бұрын
more premiers
Coding Challenge #121: Logo Interpreter
41:07
The Coding Train
Рет қаралды 60 М.
The bit shift operators in C
12:39
CodeVault
Рет қаралды 23 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Coding Challenge #117: Seven-Segment Display
18:11
The Coding Train
Рет қаралды 144 М.
Intro to Binary and Bitwise Operators in C++
21:40
The Cherno
Рет қаралды 140 М.
Collisions Without a Physics Library! (Coding Challenge 184)
31:05
The Coding Train
Рет қаралды 138 М.
Bitwise Operators and WHY we use them
8:41
Alex Hyett
Рет қаралды 100 М.
Wave Function Collapse: Overlapping Model
1:32:09
The Coding Train
Рет қаралды 22 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 126 М.
Bitwise Operations & Bit Masking
13:08
Learn Learn Scratch Tutorials
Рет қаралды 39 М.
Coding Challenge #127: Brownian Tree Snowflake
19:25
The Coding Train
Рет қаралды 81 М.
Coding Challenge #90: Floyd-Steinberg Dithering
28:51
The Coding Train
Рет қаралды 441 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН