Discuss Scratch
- Discussion Forums
- » Suggestions
- » new block: (( ) in base ( ))
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
I think that Scratch should have this block:
one thing that this block would be useful for is making a calculator that can show answers in bases like base 20, which is still used today.
([] in base (... v) :: operators)this block will convert any number (as long as it's an integer) into any base between 1 (unitary) and 36 (hexatrigesimal). as for a workaround? I don't know.
one thing that this block would be useful for is making a calculator that can show answers in bases like base 20, which is still used today.
Last edited by chrdagos (Feb. 11, 2020 22:18:46)
- hedgehog_blue
-
Scratcher
1000+ posts
new block: (( ) in base ( ))
This would be useful for changing the form of data for save codes or to be able to be stored in cloud variables. Currently, base conversion requires a slow process taking up multiple variables/custom blocks with a chance of becoming incorrect because of an inability to keep precision on larger numbers. Maybe allow the original base to be specified though.
(convert [] from base (... v) to base (... v) ::operators)
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
This would be useful for changing the form of data for save codes or to be able to be stored in cloud variables. Currently, base conversion requires a slow process taking up multiple variables/custom blocks with a chance of becoming incorrect because of an inability to keep precision on larger numbers. Maybe allow the original base to be specified though.hmm, that's a great idea!(convert [] from base (... v) to base (... v) ::operators)
- minor-edit
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Scratch has built-in conversion from hexadecimal, octal, and binary to base ten.
Base conversion is a nice project.
None of the operators have three inputs. (Glide may be the only block, not counting lists.) In simpler blocks:
The second input, base, would be like on the repeat block.
(round (join [0x] [10])) // 16
(round (join [0o] [10])) // 8
(round (join [0b] [10])) // 2
Base conversion is a nice project.
None of the operators have three inputs. (Glide may be the only block, not counting lists.) In simpler blocks:
([A] from base (16) :: operators) // report a number
((10) to base (16) :: operators) // report a string
The second input, base, would be like on the repeat block.
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Scratch has built-in conversion from hexadecimal, octal, and binary to base ten.o.k, but a dropdown is better than having to type the b's and o's and x's.(round (join [0x] [10])) // 16
(round (join [0o] [10])) // 8
(round (join [0b] [10])) // 2
Base conversion is a nice project.
None of the operators have three inputs. (Glide may be the only block, not counting lists.) In simpler blocks:([A] from base (16) :: operators) // report a number
((10) to base (16) :: operators) // report a string
The second input, base, would be like on the repeat block.
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
and these workarounds only convert from base 10, not from a given baseScratch has built-in conversion from hexadecimal, octal, and binary to base ten.o.k, but a dropdown is better than having to type the b's and o's and x's.(round (join [0x] [10])) // 16
(round (join [0o] [10])) // 8
(round (join [0b] [10])) // 2
Base conversion is a nice project.
None of the operators have three inputs. (Glide may be the only block, not counting lists.) In simpler blocks:([A] from base (16) :: operators) // report a number
((10) to base (16) :: operators) // report a string
The second input, base, would be like on the repeat block.
Last edited by chrdagos (Feb. 13, 2020 20:28:40)
- -FasterThanLight-
-
Scratcher
100+ posts
new block: (( ) in base ( ))
Can you please provide a reason that this would be useful? Perhaps two?
- minor-edit
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Same simpler blocks with new labels:
The input of base would have a dropdown like on the repeat block.
(decode [FF] base (16) :: operators) // report a number
(encode (255) to base (16) :: operators) // report a string
The input of base would have a dropdown like on the repeat block.
- Seth_Zaw
-
Scratcher
100+ posts
new block: (( ) in base ( ))
Base-1 (unitary) isn't possible.
BTW, here's a workaround:
BTW, here's a workaround:
define (n) in base (b)
set [result v] to []
set [num v] to ([abs v] of (n))
repeat until <(num)=[0]>
set [result v] to (join(letter(((num)mod(b))+(1))of[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ])(result))
set [num v] to ([floor v] of ((num)/(b))
end
if <(n)<[0]> then
set [result v] to (join[-](result))
end
- badatprogrammingibe
-
Scratcher
500+ posts
new block: (( ) in base ( ))
No support as per the reasons below.
It is a fun and interesting exercise and challenge for novice programmers to complete; there is such little practical use for it, that its use as an exercise and a challenge outweighs its possible uses in projects.
It is a fun and interesting exercise and challenge for novice programmers to complete; there is such little practical use for it, that its use as an exercise and a challenge outweighs its possible uses in projects.
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Base-1 (unitary) isn't possible.incorrect. base 1 is possible. however, it isn't practical because…
1 in unitary is 1
2 in unitary is 11
3 in unitary is 111
4 in unitary is 1111
and so on…
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Same simpler blocks with new labels:those blocks suggest to me that they involve cryptography, not base conversion…(decode [FF] base (16) :: operators) // report a number
(encode (255) to base (16) :: operators) // report a string
The input of base would have a dropdown like on the repeat block.
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Base-1 (unitary) isn't possible.but this so-called “workaround” doesn't allow you to choose the base that you are converting FROM
BTW, here's a workaround:define (n) in base (b)
set [result v] to []
set [num v] to ([abs v] of (n))
repeat until <(num)=[0]>
set [result v] to (join(letter(((num)mod(b))+(1))of[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ])(result))
set [num v] to ([floor v] of ((num)/(b))
end
if <(n)<[0]> then
set [result v] to (join[-](result))
end
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
plus if the number that is being converted isn't a integer, the script fails completelyBase-1 (unitary) isn't possible.but this so-called “workaround” doesn't allow you to choose the base that you are converting FROM
BTW, here's a workaround:define (n) in base (b)
set [result v] to []
set [num v] to ([abs v] of (n))
repeat until <(num)=[0]>
set [result v] to (join(letter(((num)mod(b))+(1))of[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ])(result))
set [num v] to ([floor v] of ((num)/(b))
end
if <(n)<[0]> then
set [result v] to (join[-](result))
end
- Sheep_maker
-
Scratcher
1000+ posts
new block: (( ) in base ( ))
Same simpler blocks with new labels:Could merge them into a single block:(decode [FF] base (16) :: operators) // report a number
(encode (255) to base (16) :: operators) // report a string
The input of base would have a dropdown like on the repeat block.
(convert [FF] from base (16 v) to base (10 v)::operators)
(convert [255] from base (10 v) to base (16 v)::operators)
Under the base system that our numbers use, the digits of base n should be from 0 to n - 1, so base 1 should only have the digit 0, and a number should be the sum of a digit times n to the power of the digit position. Since base 1 only has the digit 0, the only number that can be represented is 0 (0000 in base 1 = 0 * 1^3 + 0 * 1^2 + 0 * 1^1 + 0 * 1^0 = 0)Base-1 (unitary) isn't possible.incorrect. base 1 is possible. however, it isn't practical because…
1 in unitary is 1
2 in unitary is 11
3 in unitary is 111
4 in unitary is 1111
and so on…
Of course, that doesn't mean your base system doesn't exist or is incorrect; rather, it doesn't fit with the other bases that the block converts numbers between
- minor-edit
-
Scratcher
500+ posts
new block: (( ) in base ( ))
Could merge them into a single block:True, but the number of inputs would be atypical.(convert [FF] from base (16 v) to base (10 v)::operators)
None of the operators have three inputs. (Glide may be the only block, not counting lists.)
- chrdagos
-
Scratcher
500+ posts
new block: (( ) in base ( ))
True, but the number of inputs would be atypical.well, the block would need at lease 3 inputs to operate right. I mean, how does one convert a number to base-8 if they don't know what number they are converting?
- Discussion Forums
- » Suggestions
-
» new block: (( ) in base ( ))






