Base64 difference between C# and Java

后端 未结 3 995
陌清茗
陌清茗 2021-01-13 20:16

image is the string of an image file .

I have code as follows in C#:

Convert.ToBase64String(image);

and code as follows in

3条回答
  •  半阙折子戏
    2021-01-13 20:30

    First you need to realise that a byte stores 256 values whether its signed or unsigned. If you want to get unsigned values from a signed byte (which is what Java supports) you can use & 0xFF

    e.g.

    byte[] bytes = { 0, 127, -128, -1};
    for(byte b: bytes) {
      int unsigned = b & 0xFF;
      System.out.println(unsigned);
    }
    

    prints

    0
    127
    128
    255
    

    The simple answer is you don't need a byte[] which has the same values. ;)

提交回复
热议问题