#Hyper-optimized Telemetry exercise struggling

10 messages · Page 1 of 1 (latest)

next star
#

My code :


public static class TelemetryBuffer
{
    public static byte[] ToBuffer(long reading)
    {
        return BitConverter.GetBytes(reading);
    }

    public static long FromBuffer(byte[] buffer)
    {
        return BitConverter.ToInt64(buffer, 0);
    }
}```
Return not a single solution, the first one test return:
var bytes = TelemetryBuffer.ToBuffer(Int64.MaxValue);
Assert.Equal(new byte[] { 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }, bytes);
Assert.Equal() Failure: Collections differ
           ↓ (pos 0)
Expected: [248, 255, 255, 255, 255, ···]
Actual:   [255, 255, 255, 255, 255, ···]
           ↑ (pos 0)

And I have no idea what is wrong, since the task should be simple because  it is introductory exercise
quaint prawn
#

What track is this?

#

Your code doesn't do any of the encoding. You appear to just be returning the input data directly.

#

There's an IntMax example in the instructions:

// Type: int, bytes: 4, signed: yes, prefix byte: 256 - 4
TelemetryBuffer.ToBuffer(Int32.MaxValue)
// => {0xfc, 0xff, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0 };
#

Note when called with a Max value, the first byte is not 0xff.

next star
#

Yeah, you are right. It seems I didn't understand the task correctly, I will work on that.
Thank you

quaint prawn
#

You're welcome

#

Which track is this?

final flaxBOT
#

If everything is resolved, we ask that the person who posted the request react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

lethal field
#

it's C#