如何将字符串转换为位然后转换为int数组 - java [英] How to convert string into bits and then into int array - java

查看:159
本文介绍了如何将字符串转换为位然后转换为int数组 - java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java中将字符串转换为位(不是字节)或位数组(我将在稍后进行一些操作)以及如何转换为整数数组(每32位转换为int然后将其放入数组中) ?我从未在Java中进行过这种转换。

How to convert string into bits(not bytes) or array of bits in Java(i will do some operations later) and how to convert into array of ints(every 32 bits turn into the int and then put it into the array? I have never done this kind of conversion in Java.

String->array of bits->(some operations I'll handle them)->array of ints


推荐答案

ByteBuffer bytes = ByteBuffer.wrap(string.getBytes(charset));
  // you must specify a charset
IntBuffer ints = bytes.asIntBuffer();
int numInts = ints.remaining();
int[] result = new int[numInts];
ints.get(result);

这篇关于如何将字符串转换为位然后转换为int数组 - java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆