标签: byte

字节[]到字符串到字节数组转换在java中不能正常工作

我有一个像这样初始化的字节数组:

public static byte[] tmpIV =  {0x43, (byte)0x6d, 0x22, (byte)0x9a, 0x22,
                         (byte)0xf8, (byte)0xcf, (byte)0xfe, 0x15, 0x21,
                         (byte)0x0b, 0x38, 0x01, (byte)0xa7, (byte)0xfc, 0x0e};
Run Code Online (Sandbox Code Playgroud)

如果我打印它给我

67   109    34      -102       34     -8          -49      -2      21      33
11    56    1       -89       -4      14
Run Code Online (Sandbox Code Playgroud)

然后我将整个字节数组转换为字符串并发送给我的朋友.

String str = new String(tmpIV);
Run Code Online (Sandbox Code Playgroud)

我的朋友是C#程序员

所以我的朋友得到了一些其他数据.我的朋友将如何获得与我发送的数据相同的数据.另外在Java中如果我将上面的字符串重新转换为字节数组,我没有得到我发送的确切字符串:

 67     109        34        -17        -65      -67      34       -17     -65       -67
-17     -65        -67        -17         -65    -67      21       33    11     56      1
-17      -65      -67         -17       -65       -67   
Run Code Online (Sandbox Code Playgroud)

c# java byte

3
推荐指数
1
解决办法
3705
查看次数

当某些字节错误时,BitmapFactory.decodeStream(inputStream)始终返回null

我正在构建一个Android应用程序,我目前无法从URL中检索位图.这是我正在使用的代码:

public static Bitmap bmpFromURL(URL imageURL){

    Bitmap result = null;

    try {

        HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection();

        connection.setDoInput(true);

        connection.connect();

        InputStream input = connection.getInputStream();

        result = BitmapFactory.decodeStream(input);


    } catch (IOException e) {


        e.printStackTrace();

    }

    return result;

}
Run Code Online (Sandbox Code Playgroud)

当图片写入时,一切正常,但是当某些字节错误时,结果为空.我认为这基本上是可以预料的,因为它是在以下文档中写的BitmapFactory.decodeStream:

如果输入流为空,或者不能用于解码位图,则该函数返回null.流的位置将是读取编码数据后的位置.

问题是,我的错误图片很好地解释了我的网络浏览器,我可以在iPhone平台上这样做.

有没有办法忽略那些错误的像素?也许有选项参数?

任何帮助赞赏

罗曼

java android byte inputstream bitmap

3
推荐指数
1
解决办法
3024
查看次数

字符串到字节[delphi]

我需要将数据存储到内存中.我的数据类型数据是字符串.我想最小化内存使用量.我想我必须将字符串更改为字节.我对吗?如果我将字符串转换为字节,这意味着我必须将字符串转换为TMemoryStream?

delphi byte

3
推荐指数
1
解决办法
1万
查看次数

将Byte []转换为int

我有这个方法将有符号或无符号转换byte为int,但它不返回它应该返回的内容.有人可以在下面的代码中指出问题吗?

public int convertByteToInt(byte[] b){          
    int value= 0;
    for(int i=0;i<b.length;i++){                
    int n=(b[i]<0?(int)b[i]+256:(int)b[i])<<(8*i);             
        value+=n;
    }         
    return value;       
}
Run Code Online (Sandbox Code Playgroud)

编辑:

我正在读取一个wav文件以计算SNR.转换返回的值应该在0到255之间给出一些东西.应用程序应该比较2个wave文件,on是orignal one,另一个是修改的并计算SNR.

java int signed byte

3
推荐指数
2
解决办法
4万
查看次数

如何在没有arraycopy的情况下使用byte []的一部分?

我想知道如何在没有arraycopy的情况下使用byte []的一部分?

用C语言

char buf[100];
int i;

for (i = 0; i < 100; i += 10) {
    proc(buf + i);
}
Run Code Online (Sandbox Code Playgroud)

但在Java中,

byte[] buf = new byte[100];
int i;

for (i = 0; i < 100; i += 10) {
    proc(buf + i);
}
Run Code Online (Sandbox Code Playgroud)

不行.

byte[] buf = new byte[100];
int i;

for (i = 0; i < 100; i += 10) {
    byte[] temp = new byte[10];
    System.arraycopy(buf, i, temp, 0, 10);
    proc(temp);
}
Run Code Online (Sandbox Code Playgroud)

只有工作.

但是,我不喜欢arraycopy. …

java byte

3
推荐指数
2
解决办法
8154
查看次数

程序在内部查看文件中的字节

你知道是否存在一个程序或方法来查看文本,html文件中的(secuences)字节?不是看字符,而是看完整的字节序列.

建议?

byte text editor

3
推荐指数
1
解决办法
3793
查看次数

如何使用Perl以字节数组的形式读取图像?

我的Perl经验非常少.

我需要读取二进制图像并将其传递给Image::ExifTool模块.

这是我的代码:

use Image::ExifTool;

my $exifTool = new Image::ExifTool; 

open(IMAGE, $file) || die "Can't Open $file\n";
binmode(IMAGE);

my ($buf, $data, $n);
while (($n = read FILE, $data, 4) != 0) {
  $buf .= $data;
}

#'.=' is concat
print $file .= " test";

$infob = $exifTool->ImageInfo(\$buf);

foreach ( keys %$infob ) {
    print "$_ => $$infob{$_}\n";
}

close(IMAGE);
Run Code Online (Sandbox Code Playgroud)

据我所知,上面的代码读入了参考文件,并在二进制数据的字节级别附加$buf.

根据ExifTool文档,您可以将内存引用作为标量var传递给ImageInfo方法 - 这在上面完成.

执行时,Image :: ExifTool模块会吐出以下内容:

Error => Unknown file type
Run Code Online (Sandbox Code Playgroud)

perl byte image file

3
推荐指数
1
解决办法
2551
查看次数

如何在Python中确定"单词"大小

我需要知道Python中'word'中的字节数.我需要这个的原因是我需要从文件中读取的单词数量; 如果我知道单词中的字节数,我可以使用该file.read(num_bytes)函数从文件中读取适当的数量.

如何确定单词中的字节数?

python byte cpu-word file-read

3
推荐指数
1
解决办法
3057
查看次数

将位图数组转换为字节数组

我有一个Bitmaps数组,我试图将其转换为字节数组,其中字节数组的每个索引代表一个Bitmap.我在弄清楚如何做到这一点时遇到了一些麻烦.如果有人有任何建议,请告诉我.谢谢!

private void ConvertBitmapToBytes(Bitmap[] BitmapArray)
{
    byte[][] BitmapBytes = new byte[BitmapArray.Length][];
    ImageConverter convert = new ImageConverter();
    for (int i = 0; i < BitmapArray.Length; i++)
    {
        BitmapBytes[i] = new byte[BitmapArray.Length];
        BitmapBytes[i][i] = convert.ConvertTo(BitmapArray[i], typeof(byte[]));
    }
}
Run Code Online (Sandbox Code Playgroud)

c# arrays byte

3
推荐指数
1
解决办法
167
查看次数

C中的位,字节,字符和整数大小

从我在Google协议流程中搜索和发现的内容,我已经看到一个字符总是1个字节.这是肯定的.但是,我也看到它可能不是8位(可能更大,见CHAR_BITS).这是否意味着,如果它是,比如10位,在一些假设的架构中,那么1个字节= 10位?这是否意味着如果实现将整数默认为4个字节,那么int的大小将是40位?尽管互联网上的线程数量非常疯狂,但我对所有这些位字节变化都有点不满.

c primitive byte bit

3
推荐指数
1
解决办法
187
查看次数

标签 统计

byte ×10

java ×4

c# ×2

android ×1

arrays ×1

bit ×1

bitmap ×1

c ×1

cpu-word ×1

delphi ×1

editor ×1

file ×1

file-read ×1

image ×1

inputstream ×1

int ×1

perl ×1

primitive ×1

python ×1

signed ×1

text ×1