如何从字节数组转换为Word数组在C [英] How to convert from byte array to word array in c

查看:548
本文介绍了如何从字节数组转换为Word数组在C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C,我如下定义了一个字节和字:

Using c, I have defined a byte and word as follows:

typedef unsigned char byte;
typedef union {
    byte b[4];
    unsigned long w;
} word;

这让我很容易去从词字节,但是我不知道的一个好办法,走另一条路。是否有可能做这样的事从字节*强制转换为WORD *或者我必须坚持反复复制字节的话吗?

This allows me to easy go from words to bytes, but I'm not sure of a good way to go the other way. Is it possible to do something like cast from byte* to word* or do I have to stick with iteratively copying bytes to words?

推荐答案

一个关于C是你可以采取一个空指针并将其转换为任何伟大而可怕的事情。只要你知道自己在做什么工作,但要在习惯得到不是。

One of the great and terrible things about c is you can take a void pointer and cast it to anything. As long as you know what you are doing it will work, but not something you want to get in the habit of.

这篇关于如何从字节数组转换为Word数组在C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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