scala 字符串转换数组_如何在Scala中将十六进制字符串转换为字节数组?
scala 字符串转换数组
Hex String in Scala denotes value in hexadecimal number system i.e. base 16 number system.
Scala中的十六进制字符串表示以十六进制数表示的值,即以16进制数表示的系统。
Example:
例:
hexString = "32AF1"
Byte Array is an array that stores elements of byte data type.
字节数组是一个存储字节数据类型元素的数组。
将十六进制字符串转换为字节数组 (Converting Hex String to Byte Array)
We can convert a hex string to a byte array in Scala using some method from java libraries which is valid as Scala uses the java libraries for most of its functions.
我们可以使用Java库中的某些方法在Scala中将十六进制字符串转换为字节数组,这是有效的,因为Scala将Java库用于其大多数功能。
Step 1: Convert hexadecimal string to int
步骤1: 将十六进制字符串转换为int
Step 2: Convert integer value to byte array using the toByteArray method for BigInteger values.
步骤2:使用BigInteger值的toByteArray方法将整数值转换为字节数组。
Program:
程序:
import scala.math.BigInt
object MyClass {def main(args: Array[String]) {val hexString = "080A4C";
println("hexString : "+ hexString)
val integerValue = Integer.parseInt(hexString, 16)
val byteArray = BigInt(integerValue).toByteArray
println("The byte Array for the given hexString is : ")
for(i <- 0 to byteArray.length-1 )
print(byteArray(i)+ " ")
}
}
Output:
输出:
hexString : 080A4C
The byte Array for the given hexString is :
8 10 76
Description:
描述:
In the above code, we have a hexadecimal string named hexString, and then convert it to integer value using parseInt() method of Integer class and stored the value to a variable named integerValue. We will convert this integer value to byteArray using the toByteArray method of BigInt class and store it to a variable named byteArray and printed the value using print() method.
在上面的代码中,我们有一个名为hexString的十六进制字符串,然后使用Integer类的parseInt()方法将其转换为整数值,并将该值存储到一个名为integerValue的变量中。 我们将使用BigInt类的toByteArray方法将此整数值转换为byteArray,并将其存储到名为byteArray的变量中,并使用print()方法打印该值。
翻译自: https://www.includehelp.com/scala/convert-hex-string-to-byte-array.aspx
scala 字符串转换数组
scala 字符串转换数组_如何在Scala中将十六进制字符串转换为字节数组?相关推荐
- python列表转字节_如何在Python中将十进制数转换为字节列表
How do you turn a long unsigned int into a list of four bytes in hexidecimal? Example... 777007543 = ...
- scala 字符串转换数组_如何在Scala中将字节数组转换为字符串?
scala 字符串转换数组 Byte Array in Scala is an array of elements of a byte type. String in Scala is a colle ...
- scala 字符串占位符_如何在Scala中将带有换行符的字符串转换为字符串列表?
scala 字符串占位符 A string is a sequence of characters and it can contain multiple lines, for this, the s ...
- scala集合中添加元素_如何在Scala中将元素添加到列表中?
scala集合中添加元素 In Scala, lists are immutable data structures in which adding new elements is not allow ...
- python字符串筛选输出_如何在Python中过滤字符串列表
Python使用列表数据类型在顺序索引中存储多个数据.它的工作方式类似于其他编程语言的数字数组.filter()方法是Python的一种非常有用的方法.可以使用filter()方法从Python中的任 ...
- javascript字典中添加数组_如何在 JavaScript 中更好地使用数组
在 freeCodeCamp 社区阅读原文. 本文短小精悍,我保证.在过去的数个月里,我注意到在我审阅的 pull request 中有四个(关于数组使用的)错误经常出现.同时,我自己也会犯这些错误, ...
- python字符串转整数_如何在Python中将字符串转换为整数
Python中的所有数据类型(包括整数和字符串)都是对象.通常在编写Python代码时,您需要将一种数据类型转换为另一种数据类型.例如,要对表示为字符串的数字进行数学运算,需要将其转换为整数. 在本教 ...
- scala 随机生成整数_如何在Scala中以整数形式获取当前年份?
scala 随机生成整数 In Scala programming language, there is an option for the programmer to use libraries o ...
- scala集合中添加元素_如何在Scala中获得列表的第一个元素?
scala集合中添加元素 清单 (List) A list is a linear data structure. It is a collection of elements of the same ...
最新文章
- CentOS yum 源的配置与使用
- 为了熟悉再一次的配置Postfix
- xpath如何得到【爬虫】
- Python第一弹--------初步了解Python
- 通过Windows Azure Connect ,实现本地机器与Windows Azure 虚拟机的相互连接(转+译)...
- dell服务器r730安装esxi系统,安装Esxi系统重装Esxi系统
- 灵山奇缘服务器维护,灵山奇缘1月8日更新了什么 灵山奇缘1月8日更新维护内容一览...
- HIVE 的笛卡尔积on无条件
- mysql八大知识点_MySQL索引八大法则之上篇
- 系统服务器iis如何启动不了,无法启动win7系统下IIS服务器怎么办
- ps入门第8天_ps通道_颜色通道Alpha通道 案例:通道抠图
- 2022-10-10更新步数接口和快捷指令
- 考研英语-旧题高频词(齐雪妮老师)-2020-02-27,03-05,03-12,03-19
- 奈奎斯特采样定理粗略推导
- root用户修改root密码提示The password fails the dictionary check
- java阶梯计费,机器智能审核阶梯计费方式
- 手机触屏事件(jquery)
- CAD2018安装计算机黑屏,3dmax2018一打开就闪退的三种原因和解决方法
- 华科CPP慕课SPOC第七章 编程题3
- 网安渗透安服 电脑 环境 配置 一文全
热门文章
- java 文件下载方法_【工具类】Java后台上传下载文件的几种方式
- 计算机文化基础重点知识归纳,计算机文化基础_第二章重点知识总结(考试必备!!!)...
- SmoothNLP 中文NLP文本处理工具 Python 实战示范
- 《Java设计模式》之桥接模式
- Centos 7安装与配置nagios监控(一)
- docker 磁盘问题:device or resource busy
- 关于JAVA中的synchronized,一段不错的解释...
- oracle 10g学习之分组函数
- 【Microsoft Azure学习之旅】测试消息队列(Service Bus Queue)是否会丢消息
- 数据数据库学通MongoDB——第一天 基础入门