7.1 Display the binary cards needed to represent a decimal number between 0 and 31

Scratch solution

View solution

This is just one of many possible solutions:

whenclickedaskPlease enter a number between 0 and 31:andwaitsetnumbertoanswersetbit valueto32setcardstorepeatuntilbitvalue=1setbit valuetobitvalue/2ifnumber>bitvalueornumber=bitvaluethensetcardstojoincardsWsetnumbertonumber-bitvalueelsesetcardstojoincardsBsayjoinjoinjoinThe binary representation for the number answer is cards

Back to programming challenge