FD小工具代码-hex2bin

本文介绍了一个用于将十六进制数转换为二进制数的简单工具,并展示了其使用方法及输出示例。

为了某件事写了个小工具,顺手扔进FD工具箱中。


/*
输入十六进制,输出二进制
*/


#include <ctype.h>
#include <stdio.h>

#define H0 "0000 "
#define H1 "0001 "
#define H2 "0010 "
#define H3 "0011 "
#define H4 "0100 "
#define H5 "0101 "
#define H6 "0110 "
#define H7 "0111 "
#define H8 "1000 "
#define H9 "1001 "
#define Ha "1010 "
#define Hb "1011 "
#define Hc "1100 "
#define Hd "1101 "
#define He "1110 "
#define Hf "1111 "

void hex2bin(char string[]){
	for(;*string != 0;string++){
		char temp = toupper(*string);
		switch (temp){
			case '0':
			printf(H0);
			break;
			case '1':
			printf(H1);
			break;
			case '2':
			printf(H2);
			break;
			case '3':
			printf(H3);
			break;
			case '4':
			printf(H4);
			break;
			case '5':
			printf(H5);
			break;
			case '6':
			printf(H6);
			break;
			case '7':
			printf(H7);
			break;
			case '8':
			printf(H8);
			break;
			case '9':
			printf(H9);
			break;
			case 'A':
			printf(Ha);
			break;
			case 'B':
			printf(Hb);
			break;
			case 'C':
			printf(Hc);
			break;
			case 'D':
			printf(Hd);
			break;
			case 'E':
			printf(He);
			break;
			case 'F':
			printf(Hf);
			break;
			default:
			printf("ERR");
			return;
			break;
		}
	}	
}



int main(int argc, char **argv){
	for(int i = 1; i <argc; i++){
		printf("0x%s: ", argv[i]);
		hex2bin(argv[i]);
		puts("");
	}
	return 0;
}


输出示例:


bogon:desktop firedom$ ./FDhex2bin 6000 1234 fdfdfdfd abcdefg

0x6000: 0110 0000 0000 0000 

0x1234: 0001 0010 0011 0100 

0xfdfdfdfd: 1111 1101 1111 1101 1111 1101 1111 1101 

0xabcdefg: 1010 1011 1100 1101 1110 1111 ERR


w@w-virtual-machine:~/桌面/cmk/Main/build$ make [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o [100%] Linking CXX executable main /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: CMakeFiles/main.dir/main.cpp.o: in function `main': main.cpp:(.text+0x10): undefined reference to `TM1650_Init()' /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: main.cpp:(.text+0x14): undefined reference to `Display_Init()' /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: main.cpp:(.text+0x1c): undefined reference to `Display_Change_Brightness(unsigned char)' /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: main.cpp:(.text+0x60): undefined reference to `uart_init(char const*, int)' /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: main.cpp:(.text+0xfc): undefined reference to `Show_Num(unsigned short, unsigned char)' /opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: main.cpp:(.text+0x118): undefined reference to `uart_send_time_hex(int, rtc_time*)' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/main.dir/build.make:100:main] 错误 1 make[1]: *** [CMakeFiles/Makefile2:87:CMakeFiles/main.dir/all] 错误 2 make: *** [Makefile:91:all] 错误 2
07-23
解释这段语句什么意思:09-22 10:54:55.564 1000 1732 18185 E subsystem_ramdump: write successful for ramdump fd for /data/vendor/bsplog/wlan/ssr_dump/2025-09-22-10:54:41/ramdump_wpss_2025-09-22_10-54-50.elf 09-22 10:54:55.564 1000 1732 18185 E subsystem_ramdump: read /proc/last_mcrash :adrastea/wpss.mdt: cmnos_thread.c:4003:Asserted in wal_power_debug.c:wal_power_debug_trigger_crash_c 09-22 10:54:55.564 1000 1732 18185 E subsystem_ramdump: /data/vendor/ramdump/mcrash_history is Max, can NOT save more 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: Event AVOID_FREQUENCIES (48) received 09-22 10:54:55.564 wifi 3431 3431 I wpa_supplicant: p2p0: CTRL-EVENT-AVOID-FREQ ranges= 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: P2P: Update channel list based on frequency avoid event 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: Determining shared radio frequencies (max len 2) 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: Shared frequencies (len=0): completed iteration 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: Determining shared radio frequencies (max len 2) 09-22 10:54:55.564 wifi 3431 3431 D wpa_supplicant: p2p0: Shared frequencies (len=0): completed iteration 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: p2p0: Shared frequencies (len=0): valid for P2P 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 81 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=13): 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 115 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=4): 24 28 2c 30 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 116 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 24 2c 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 117 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 28 30 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 118 (client only) 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=4): 34 38 3c 40 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 119 (client only) 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=2): 34 3c 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 120 (client only) 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=2): 38 40 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 124 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=4): 95 99 9d a1 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 125 09-22 10:54:55.565 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=5): 95 99 9d a1 a5 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 126 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 95 9d 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 127 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 99 a1 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 128 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=8): 24 28 2c 30 95 99 9d a1 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 130 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 130 (client only) 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=9): 24 28 2c 30 95 99 9d a1 a5 09-22 10:54:55.566 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=4): 34 38 3c 40 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: P2P: Update channel list 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: P2P: channels: 81:1,2,3,4,5,6,7,8,9,10,11,12,13 115:36,40,44,48 116:36,44 117:40,48 124:149,153,157,161 125:149,153,157,161,165 126:149,157 127:153,161 128:36,40,44,48,149,153,157,161 130:36,40,44,48,149,153,157,161,165 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: P2P: cli_channels: 118:52,56,60,64 119:52,60 120:56,64 130:52,56,60,64 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: nl80211: Drv Event 103 (NL80211_CMD_VENDOR) received for wlan0 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: nl80211: Vendor event: wiphy=0 vendor_id=0x1374 subcmd=10 09-22 10:54:55.567 wifi 3431 3431 D wpa_supplicant: wlan0: Event AVOID_FREQUENCIES (48) received 09-22 10:54:55.568 wifi 3431 3431 I wpa_supplicant: wlan0: CTRL-EVENT-AVOID-FREQ ranges= 09-22 10:54:55.568 wifi 3431 3431 D wpa_supplicant: wlan0: P2P: Update channel list based on frequency avoid event 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: wlan0: Determining shared radio frequencies (max len 2) 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: wlan0: Shared frequencies (len=0): completed iteration 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: wlan0: Determining shared radio frequencies (max len 2) 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: wlan0: Shared frequencies (len=0): completed iteration 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: wlan0: Shared frequencies (len=0): valid for P2P 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 81 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=13): 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 115 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=4): 24 28 2c 30 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 116 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 24 2c 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 117 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 28 30 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 118 (client only) 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=4): 34 38 3c 40 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 119 (client only) 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=2): 34 3c 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 120 (client only) 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=2): 38 40 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 124 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=4): 95 99 9d a1 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 125 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=5): 95 99 9d a1 a5 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 126 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 95 9d 09-22 10:54:55.569 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 127 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=2): 99 a1 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 128 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=8): 24 28 2c 30 95 99 9d a1 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 130 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Add operating class 130 (client only) 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Channels - hexdump(len=9): 24 28 2c 30 95 99 9d a1 a5 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Channels (client only) - hexdump(len=4): 34 38 3c 40 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: Update channel list 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: channels: 81:1,2,3,4,5,6,7,8,9,10,11,12,13 115:36,40,44,48 116:36,44 117:40,48 124:149,153,157,161 125:149,153,157,161,165 126:149,157 127:153,161 128:36,40,44,48,149,153,157,161 130:36,40,44,48,149,153,157,161,165 09-22 10:54:55.570 wifi 3431 3431 D wpa_supplicant: P2P: cli_channels: 118:52,56,60,64 119:52,60 120:56,64 130:52,56,60,64 09-22 10:54:55.581 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.600 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.604 10200 10875 11981 D JavaheapMonitor: Java heap used=4M max=256M, proc: com.miui.msa.global 09-22 10:54:55.605 10200 10875 11981 V JavaheapMonitor: Check java heap usage finished! Next check delay: 300000 09-22 10:54:55.631 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.698 1000 1732 18185 E subsystem_ramdump: chmod result:0 09-22 10:54:55.708 1000 1732 18185 I subsystem_ramdump: send file name enter 09-22 10:54:55.708 1000 1732 18185 E subsystem_ramdump: send file name open /data/vendor/ramdump/name for read error:6 09-22 10:54:55.708 1000 1732 18185 E subsystem_ramdump: ----mdm_helper cmd:chmod 777 /data/vendor/bsplog/wlan/ssr_dump/2025-09-22-10:54:41/ramdump_wpss_2025-09-22_10-54-50.elf 09-22 10:54:55.744 1000 1732 18185 E subsystem_ramdump: ----run_sh_cmd pid:18255 res:0 09-22 10:54:55.744 1000 1732 18185 E subsystem_ramdump: chmod ramdump, cmd_result:0x0 09-22 10:54:55.744 1000 1732 18185 E subsystem_ramdump: chmod cmd : chmod 777 /data/vendor/bsplog/wlan/ssr_dump/2025-09-22-10:54:41/ramdump_wpss_2025-09-22_10-54-50.elf 09-22 10:54:55.744 1000 1732 18185 E subsystem_ramdump: ----mdm_helper cmd:tar -czvf /data/vendor/bsplog/wlan/ssr_dump/2025-09-22-10:54:41/ramdump_wpss_2025-09-22_10-54-50.tgz /data/vendor/bsplog/wlan/ssr_dump/2025-09-22-10:54:41/ramdump_wpss_2025-09-22_10-54-50.elf 09-22 10:54:55.761 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.778 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.788 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.794 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.838 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.856 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.960 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:55.964 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.009 1000 1586 1586 W binder:1586_4: type=1400 audit(0.0:3769): avc: denied { search } for name="mcd" dev="dm-57" ino=859 scontext=u:r:surfaceflinger:s0 tcontext=u:object_r:mcd_data_file:s0 tclass=dir permissive=0 09-22 10:54:56.067 99000 7553 7574 E ocessService0:0: failed to create Unix domain socket: Operation not permitted 09-22 10:54:56.067 99001 12386 12409 E ocessService0:0: failed to create Unix domain socket: Operation not permitted 09-22 10:54:56.082 99003 13949 13956 E ocessService0:1: failed to create Unix domain socket: Operation not permitted 09-22 10:54:56.094 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.154 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.162 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.211 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.215 root 1280 18259 I resolv : GetAddrInfoHandler::run: {0 0 0 983040 10226 0} 09-22 10:54:56.215 root 1280 18259 I resolv : GetAddrInfoHandler::run: network access blocked 09-22 10:54:56.217 root 1280 18260 I resolv : GetAddrInfoHandler::run: {0 0 0 983040 10226 0} 09-22 10:54:56.217 root 1280 18260 I resolv : GetAddrInfoHandler::run: network access blocked 09-22 10:54:56.221 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.226 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1} 09-22 10:54:56.271 10161 4593 7978 W hsbr : [{0}] Failed to resolve name. status={1}
最新发布
09-23
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值