C语言基础 -- uint32_t

博客介绍了如何在C语言中处理32位无符号整型(uint32_t)数值,通过位移和位与操作获取高16位和低16位,然后将两者相加并以16进制形式输出。示例代码展示了具体的实现过程。

uint32_t 是一个32位的无符号整型。

使用这个类型需要加上头文件
#include <stdint.h>

unsigned int32_t 是错误的写法。

%x 是以16进制的形式来输出

例子:

我有一个32位的无符号整型的数,我想知道高16位和低16位相加的和是多少,结果以16进制输出?

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main()
{
    uint32_t i = 0x11223344;

    // i>>16    //得到高位
    // i&0xFFFF //得到低位

    //以16进制输出
    printf("0x%x.\n",((i >>16) + (i & 0xFFFF)));

    return 0;
}
#pragma once /*----------------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------------*/ #include <stdbool.h> #include <stddef.h> #include <stdint.h> /*----------------------------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------------------------*/ typedef enum { ILaS_ERROR, ILaS_OK, Ilas_BUSY, } ILaS_ReturnType; typedef struct { uint16_t NetworkNodes; uint32_t *retData; } ILaS_ReadDataResultType; typedef const struct { uint16_t firstBDCDAdr : 12; bool Switch_CSP : 1; uint8_t Event_address_allocation : 4; bool MemoryAdr : 1; bool Phaseshift : 1; bool CRCenable : 1; bool TempCmpEnable : 1; bool VoltSwing : 1; } ILaS_InitType; /*----------------------------------------------------------------------------*/ /* Signatures */ /*----------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif // ILAS API Initialization Functions ILaS_ReturnType ILaS_Network_Init_Interface(uint8_t nrOfILaSNetworks, bool pSPIMasterSlave); ILaS_ReturnType ILaS_Network_Init(const ILaS_InitType* NetworkInitPtr, ILaS_ReadDataResultType* NetworkInitResultPtr, uint8_t NetworkNr); ILaS_ReturnType ILaS_Branch_Init(const ILaS_InitType* NetworkInitPtr, ILaS_ReadDataResultType* NetworkInitResultPtr, uint8_t NetworkNr); // ILAS API Write Commands ILaS_ReturnType ILaS_NOP(uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Reset(uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Define_Mcast(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Config(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Bias(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Trig_ADC_Cal(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_ADC_DAC(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Trig_ADC_Meas(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Temp_Offset(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Cur_Ch2(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Cur_Ch1(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Cur_Ch0(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Hi_Ch2(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Hi_Ch1(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Hi_Ch0(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Low_Ch2(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Low_Ch1(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Low_Ch0(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Max_Ch3(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_TC_Base(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_TC_Offset(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_TC_LUT(uint8_t LUT_Adr, uint16_t LUT_Value, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Burn_Item(uint8_t BurnItem, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_3PWM_Hi(uint8_t CTRL_Hi_Ch2, uint8_t CTRL_Hi_Ch1, uint8_t CTRL_Hi_Ch0, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_3PWM_Low(uint8_t CTRL_Low_Ch2, uint8_t CTRL_Low_Ch1, uint8_t CTRL_Low_Ch0, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_DIM(uint8_t DIM_Ch2, uint8_t DIM_Ch1, uint8_t DIM_Ch0, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_PWM_Ch3(uint32_t CTRL_Ch3, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Write_Register(uint16_t RegVal, uint16_t RegAdd, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Burn_Register(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Fw_Mode(uint8_t FwMode, uint8_t NrOfLA, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Ps_Mode(uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Sig_High(uint8_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Burn_Sig(uint16_t Param, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Burn_Sniff_Mode(uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Set_Port(bool CP_CSP, bool CP_ESP, uint16_t Address, uint16_t NetworkNr); // ILAS Read Commands ILaS_ReturnType ILaS_Branch_Read_Temp(ILaS_ReadDataResultType* BranchTempPtr, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Branch_Read_Status(ILaS_ReadDataResultType* BranchStatusPtr, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Branch_Read_ADC(ILaS_ReadDataResultType* BranchADCPtr, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Branch_Read_Item(uint8_t Param, ILaS_ReadDataResultType* BranchItemPtr, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Branch_Read_PWM(ILaS_ReadDataResultType* BranchPWMPtr, uint8_t Param, bool Byte, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Network_Ping(ILaS_ReadDataResultType* NetworkPingPtr, uint16_t NetworkNr); ILaS_ReturnType ILaS_Branch_Ping(ILaS_ReadDataResultType* BranchPingPtr, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Read_Register(ILaS_ReadDataResultType* ReadRegisterPtr, uint16_t RegAdd, uint16_t Address, uint16_t NetworkNr); ILaS_ReturnType ILaS_Read_Event(ILaS_ReadDataResultType* ReadEventPtr, uint16_t NetworkNr); ILaS_ReturnType ILaS_BranchDevices_Read(ILaS_ReadDataResultType* BranchDevicesReadPtr, uint16_t RegAdd, uint16_t NetworkNr); #ifdef __cplusplus } #endif /*----------------------------------------------------------------------------*/ /* EOF */ /*----------------------------------------------------------------------------*/
05-30
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xuechanba

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值