Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Binary To Decimal Converter.js #456

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Pradeep567iaf
Copy link
Contributor

This parser is a Binary to Decimal Converter designed to parse user input in a specific format and convert binary values to decimal. By providing a command with a binary code, this parser uses an external API to fetch and return the decimal equivalent.

Activation Example
To use this converter, simply enter the command in this format:

!converttoDecimal <binary_code>

For example:
!converttoDecimal 1011

Features
Regex-based Command Parsing: The parser validates the input command using a regular expression, ensuring only binary codes are accepted.

Binary Validation: It checks the user input for valid binary numbers.

API Call for Conversion: It uses the https://networkcalc.com/api/binary/<binary_code> API to convert binary to decimal.
Slackbot Integration: Once the conversion is complete, the decimal value is sent back to the user in formatted message.

Binary to Decimal Conversion:
• Binary value: 1011
• Decimal value: 11

This parser is a Binary to Decimal Converter designed to parse user input in a specific format and convert binary values to decimal. By providing a command with a binary code, this parser uses an external API to fetch and return the decimal equivalent.

Activation Example
To use this converter, simply enter the command in this format:

!converttoDecimal <binary_code>

For example:
!converttoDecimal 1011

Features
Regex-based Command Parsing: The parser validates the input command using a regular expression, ensuring only binary codes are accepted.

Binary Validation: It checks the user input for valid binary numbers.

API Call for Conversion: It uses the https://networkcalc.com/api/binary/<binary_code> API to convert binary to decimal.
Slackbot Integration: Once the conversion is complete, the decimal value is sent back to the user in  formatted message.

*Binary to Decimal Conversion:*
• Binary value: 1011
• Decimal value: 11
Copy link
Contributor

@SapphicFire SapphicFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I have applied the hacktoberfest-accepted label which will mark this PR as accepted for you. However, there is a few changes that would be required before we can merge this.

Comment on lines 2 to 3
activation_example:!converttoDecimal <binary_code>
regex:^!converttoDecimal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this capitalisation, as this adds confusion when compared to all other parsers. Additionally, it is not clear that this parser converts from binary to decimal. It might be worthwhile making it something like !bin2dec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I wil make changes

Comment on lines 13 to 14
var match = input.match(/!converttoDecimal (\d+)/); // check input format
var expression = match ? match[1] : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear from other details about this parser, that this will not support multiple bytes (i.e. 00110101 11111111) or breaks in the binary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will rectify the code

// check the valid binary code in if statement
if(binaryCheckregx.test(expression)){
var result = evaluateBinaryExpression(expression); // call to evaluateBinaryExpression
var DecimalresultSlackMessage = "* Binary to Decimal Conversion :*\n" + "• *Binary value*: " + expression + "\n" + "• *Decimal value*: " + result.converted + "\n"; // slack markdown message format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not use unordered lists so does not use slack markdown

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Resolve the Issue raised 
1)  Please remove this capitalisation, as this adds confusion when compared to all other parsers. Additionally, it is not clear that this parser converts from binary to decimal. It might be worthwhile making it something like !bin2dec

2) It's not clear from other details about this parser, that this will not support multiple bytes (i.e. 00110101 11111111) or breaks in the binary

3) This does not use unordered lists so does not use slack markdown

Now, this parser will accept the binary code with spaces and give output as a decimal value. Change the activation  to  !bin2dec <binary code> and also remove the slack markdown and show output as normal text.
Copy link
Contributor Author

@Pradeep567iaf Pradeep567iaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make some changes in the file. Please review the changes and accept it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants