1

This code compiles visual studio 2017 but not compile visual studio 2015. I want compile in Visual studio .Why don`t compile ? show error like as Error CS0103 The name 'b00001111' does not exist in the current context

  public IEnumerable<byte> AsUtf8()
  {
    //up to 7 bits
    if (Value <= 0x007F)
    {
        yield return (byte) Value;
        yield break;
    }

    //up to 11 bits
    if (Value <= 0x07FF)
    {
        yield return (byte) (0b11000000 | (0b00011111 & (Value >> 6))); //tag + upper 5 bits
        yield return (byte) (0b10000000 | (0b00111111 & Value)); //tag + lower 6 bits
        yield break;
    }

    //up to 16 bits
    if (Value <= 0x0FFFF)
    {
        yield return (byte) (0b11100000 | (0b00001111 & (Value >> 12))); //tag + upper 4 bits
        yield return (byte) (0b10000000 | (0b00111111 & (Value >> 6))); //tag + next 6 bits
        yield return (byte) (0b10000000 | (0b00111111 & Value)); //tag + last 6 bits
        yield break;
    }

    //up to 21 bits
    if (Value <= 0x1FFFFF)
    {
        yield return (byte) (0b11110000 | (0b00000111 & (Value >> 18))); //tag + upper 3 bits
        yield return (byte) (0b10000000 | (0b00111111 & (Value >> 12))); //tag + next 6 bits
        yield return (byte) (0b10000000 | (0b00111111 & (Value >> 6))); //tag + next 6 bits
        yield return (byte) (0b10000000 | (0b00111111 & Value)); //tag + last 6 bits
        yield break;
    }

    throw new UnsupportedCodepointException();
}
Rand Random
  • 7,300
  • 10
  • 40
  • 88
  • 5
    a) binary literals were new in C#7 or later, not available in VS2015 – H H May 23 '18 at 18:18
  • Binary literals were [introduced in C#7, it seems](https://stackoverflow.com/questions/594720/c-sharp-binary-literals). I suggest you convert those binary literals into hexadecimal literals, or go with Henk's suggestion below. – 15ee8f99-57ff-4f92-890c-b56153 May 23 '18 at 18:18
  • Binary literals was added in C# 7, part of Visual Studio 2017, you can enable the new compiler by adding a nuget package, see https://stackoverflow.com/questions/39461407/how-to-use-c7-with-visual-studio-2015 for details. In any case, why are you reimplementing UTF8 encoding? – Lasse V. Karlsen May 23 '18 at 18:18
  • 2
    b) what's wrong with `Encoding.UTF8.GetBytes(string)` ? Available in VS2001 and up. – H H May 23 '18 at 18:18
  • @HenkHolterman This one is based on `IEnumerable`, so it is "streaming"... it is a very interesting piece of code. – xanatos May 23 '18 at 18:49
  • You should be able to use https://www.binaryhexconverter.com/binary-to-hex-converter to convert binary to hex... You have to remove the 0b, like 0b00011111 is 00011111, then in the site you see that it is 1F, then you add 0x and obtain 0x1F – xanatos May 23 '18 at 18:50
  • I want to use NeoSmart.Unicode package for catch Tweet Emoji – Huseyn Hesenli May 23 '18 at 18:51
  • @HuseynHesenli You can use the nuget package without recompiling the source code: https://www.nuget.org/packages/Unicode.net – xanatos May 23 '18 at 18:56
  • @xanatos I have used the converter but now show error Severity 0b00011111 0000101100010001000100000000000000000000 Error CS1021 Integral constant is too large – Huseyn Hesenli May 23 '18 at 18:58
  • @HuseynHesenli You have used it wrongly... What did you do, paste all the binaries together? One at a time. 0b00011111 must be pasted as 00011111 then you'll get 1F, then you'll write in the source 0x1F – xanatos May 23 '18 at 18:59
  • I write code into https://codeshare.io/Unicode .can you edit my code please – Huseyn Hesenli May 23 '18 at 19:05
  • @HuseynHesenli No. If you can't even do something so much simple, then perhaps you aren't expert enough as a programmer to recompile code from github. Sometimes you have to learn to do things by yourself. – xanatos May 23 '18 at 19:09
  • @xanatos thanks for your comment, but I haven`t used bite or byte before. I don`t understand what does it mean "You have to remove the 0b, like 0b00011111 is 00011111, then in the site you see that it is 1F, then you add 0x and obtain 0x1F" – Huseyn Hesenli May 23 '18 at 19:18
  • @HuseynHesenli It is plain english. Take from the source code the numbers that begin with 0b, one at a time remove the prefix 0b, copy the obtained number in the site, convert it, take the hex number from the site, prepend the 0x prefix, paste in the source code replacing the binary number. – xanatos May 23 '18 at 19:20

0 Answers0