博客
关于我
java byte[] 的骚操作
阅读量:572 次
发布时间:2019-03-10

本文共 1078 字,大约阅读时间需要 3 分钟。

类似于C数组的操作

byte[] bytetest = {0x01,0x03};

实现C语言的常量结构体数组

class AnsData {            public byte[] req_buf;            public byte[] ans_buf;            public AnsData(byte[] str_in, byte[] str2){                req_buf = str_in;                ans_buf = str2;            }        };        AnsData[] AnsDataLib = {                new AnsData(new byte[]{0x01, 0x03}, new byte[]{0x43,0x00}),                new AnsData(new byte[]{0x01,0x07}, new byte[]{0x47,0x00}),        };

在Java编程中,常常需要模拟C语言中的结构体数组操作。以下是一个实现思路的示例:

首先,我们定义一个类`AnsData`,其中包含两个字节数组`req_buf`和`ans_buf`。通过构造函数,我们可以将输入和输出的字节数组分别赋值给相应的字段:

class AnsData {      public byte[] req_buf;      public byte[] ans_buf;      public AnsData(byte[] str_in, byte[] str2) {          req_buf = str_in;          ans_buf = str2;      }  };  AnsData[] AnsDataLib = {      new AnsData(new byte[]{0x01, 0x03}, new byte[]{0x43, 0x00}),      new AnsData(new byte[]{0x01, 0x07}, new byte[]{0x47, 0x00}),  };

通过上述代码,我们可以创建一个结构体数组`AnsDataLib`,其中每个元素都包含一个请求字节数组和一个响应字节数组。这与C语言中的结构体数组非常相似,且可以通过类的方式进行对象化管理。

在实际应用中,可以根据具体需求自定义字节数组的大小和内容,实现更复杂的操作。

转载地址:http://ifgpz.baihongyu.com/

你可能感兴趣的文章
NMAP网络扫描工具的安装与使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>