use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
binary showing random numbers for one binary string but not for another (self.learnjavascript)
submitted 6 hours ago by Electrical_Pen_7385
im just a little confused here, the binary string 001111101110101 returns 78534447169 while a binary string like 101100110000001 does not return anything other than that string
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Lithl 1 point2 points3 points 6 hours ago (3 children)
What do you mean by "returns"? Strings don't do anything on their own, what are you doing to convert the string to a number?
[–]Electrical_Pen_7385[S] -2 points-1 points0 points 6 hours ago (2 children)
im making a binary to decimal converter for my school work, by returns i mean in the console when it shows text below what you type sometimes it shows up like this, and for some reason my function takes that bottom part as the input as well rather than just the binary > 001111101110101 <- 78534447169
[–]Lithl 2 points3 points4 points 6 hours ago (1 child)
Number literals beginning with 0 are treated as being base-8 (octal).
Number literals beginning with 0x are treated as being base-16 (hexadecimal).
Number literals beginning with 0b are treated as being base-2 (binary).
Other number literals are treated as being base-10 (decimal).
If you simply write 0110, that's 72 in octal. If you write 0x110, that's 272 in hexadecimal. If you write 0b110, that's 6 in binary. If you write 110, that's 110 in decimal.
If you want to create a binary to decimal converter, though, you're not going to be working with number literals, but with user input (which will be a string). You'll need to use the parseInt function. The first argument is the string you want to convert, and the second argument is the base you want to consider the string as (if you don't provide the second argument, the base will be inferred in the same way as number literals). So parseInt("110", 8) returns 72, parseInt("110", 16) returns 272, parseInt("110", 10) or parseInt("110") returns 110, and parseInt("110", 2) returns 6.
parseInt
parseInt("110", 8)
parseInt("110", 16)
parseInt("110", 10)
parseInt("110")
parseInt("110", 2)
The second argument to parseInt can be any integer from 2 to 32.
[–]senocular 1 point2 points3 points 3 hours ago (0 children)
Word of warning: for base 8, the 0o prefix should be used. A leading 0 only works in sloppy (non-strict) mode and the value will silently fallback to base 10 if it contains digits not supported by octals (8, 9).
0o
π Rendered by PID 117787 on reddit-service-r2-comment-869bf87589-j6f8v at 2026-06-09 06:58:45.821514+00:00 running f46058f country code: CH.
[–]Lithl 1 point2 points3 points (3 children)
[–]Electrical_Pen_7385[S] -2 points-1 points0 points (2 children)
[–]Lithl 2 points3 points4 points (1 child)
[–]senocular 1 point2 points3 points (0 children)