Code War每天一练第二天
发布时间:2020-12-14 04:25:21 所属栏目:大数据 来源:网络整理
导读:Given an array of one‘s and zero‘s convert the equivalent binary value to an integer. Eg: [0,1] is treated as 0001 which is the binary representation of 1. ? Examples: 将字符数组转化成整数Testing: [0,1] == 1Testing: [0,1,0] == 2Testing:
Given an array of one‘s and zero‘s convert the equivalent binary value to an integer. Eg: [0,1] is treated as 0001 which is the binary representation of 1. ? Examples:
res = x n +x n-1 +x n-2 .......x 1 +x0
#include <stddef.h> unsigned binary_array_to_numbers(const unsigned *bits,size_t count) { unsigned res = 0; for (size_t i = 0; i < count; i++) res = res << 1 | bits[i]; return res; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |