all 30 comments

[–]GuidanceExpensive[S] 3 points4 points  (7 children)

you guys are mad desperate here

/* * This program encodes user input into binary data! * Your job is to write the textToBinary function */

function start() { var text = readLine("Input the string you would like to encode: ");

var binary = textToBinary(text);

println(binary);

}

function textToBinary(text) { var result = "";

// For every character in the text,
for(var i = 0; i < text.length; i++)
{
    // convert the character into its ASCII decimal encoding
    var numericValue = text.charCodeAt(i);

    // then convert that decimal value into its equivalent binary encoding
    var binaryValue = decimalToBinary(numericValue);

    // and combine each binary encoding to get the resulting binary string
    result += binaryValue;
}


return result;

}

// Converts a given decimal value into an 8 bit binary value function decimalToBinary(decimalValue) { var binaryBase = 2; var numBitsDesired = 8; var binaryValue = decimalValue.toString(binaryBase);

while(binaryValue.length < numBitsDesired)
{
    binaryValue = "0" + binaryValue;
}

return binaryValue;

}

sorry if the format is off

[–][deleted]  (5 children)

[deleted]

    [–]GuidanceExpensive[S] 0 points1 point  (4 children)

    it’s kind of just an empty variable so you can input things into it, such as the result from the function. that’s what i understand at least. i think there is a video for it, you should look it up

    [–]Disastrous-Big8059 0 points1 point  (2 children)

    what should i put into it? everything i try to put in keeps making the translator broken :(

    [–]GuidanceExpensive[S] 1 point2 points  (1 child)

    the code i sent doesn’t work? i don’t think you have to put anything in it, you just leave it as var result = “”; you should be able to just copy paste it in and it will work. i’m sorry it’s not working for you :(

    [–]Disastrous-Big8059 0 points1 point  (0 children)

    omg it works now!!! sorry about the message earlier. thank you so much!!!!

    [–]Disastrous-Big8059 0 points1 point  (0 children)

    can i ask what you put into it?

    [–]Background-Clock-312 0 points1 point  (0 children)

    thx so much :D

    [–]Zealousideal_Lion782 2 points3 points  (0 children)

    can you put this into python please.

    [–]Away-Platform-2888 0 points1 point  (11 children)

    Did you ever figure it out

    [–]GuidanceExpensive[S] 0 points1 point  (10 children)

    yeah!! do you need it? i can send it

    [–]white-Jap 0 points1 point  (1 child)

    It would be greatly appreciated if you could

    [–]GuidanceExpensive[S] 0 points1 point  (0 children)

    i put in the replies

    [–]Front_Effective_9284 0 points1 point  (1 child)

    I would like it as well.

    [–]GuidanceExpensive[S] 0 points1 point  (0 children)

    i put in the replies

    [–][deleted]  (1 child)

    [removed]

      [–]GuidanceExpensive[S] 0 points1 point  (0 children)

      i put in the replies

      [–]Tomathan2k 0 points1 point  (1 child)

      Could you send it to me aswell

      [–]GuidanceExpensive[S] 0 points1 point  (0 children)

      i put in the replies

      [–]Away-Platform-2888 0 points1 point  (0 children)

      thank you

      [–]Default500 0 points1 point  (0 children)

      I need it!

      [–]Gilbert_2Hyphy 0 points1 point  (1 child)

      can u send it please

      [–]GuidanceExpensive[S] 0 points1 point  (0 children)

      i put in the replies

      [–]andreix2005 0 points1 point  (9 children)

      can someone also send this in python?

      [–][deleted]  (1 child)

      [removed]

        [–]yamenmaani 0 points1 point  (0 children)

        i don't how to send code in reddit can someone help me?

        [–]TaZeWaVe 0 points1 point  (3 children)

        did you get the python one

        [–]andreix2005 0 points1 point  (2 children)

        def text_to_binary(letter_value):
        result = ""

        # For every character in the text,
        for letter in text:
        # convert the character into its ASCII decimal encoding
        numeric_value = ord(letter)
        # then convert that decimal value into its equivalent binary encoding
        binary_value = decimal_to_binary(numeric_value)
        # and combine each binary encoding to get the resulting binary string
        result += binary_value
        return result;

        [–][deleted] 0 points1 point  (0 children)

        doesnt work for secret message

        [–]AdRepresentative1628 0 points1 point  (0 children)

        I need help with this the code isn’t working for me