how to code 8 boolean variables inside a unit8

조회 수: 2 (최근 30일)
grapevine
grapevine 2012년 5월 3일
Hi everyone,
I have to code 8 boolean variables inside a 8 bit word, I should return as result an unsigned integer of 8 bit e.g.:
unit8 wordVAR;
boolean IN0;
boolean IN1;
....................
and then
8bit 7 6 5 4 3 2 1 0
wordVAR= IN7 IN6 IN5 IN4 IN3 IN2 IN1 IN0
I should do that because my internship advisor want it
is there a way to do that using a matlab instruction or a C Lv2 sfunction ?
thanks a lot 4 reading

채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 3일
You can use bitset() but it has never been clear that bitset is any faster than using arithmetic.

추가 답변 (1개)

grapevine
grapevine 2012년 5월 3일
I thought to use a stuff like that
wordVAR=IN0*pow(2,0)+IN1*pow(2,1)+IN2*pow(2,2)+IN3*pow(2,3)+.........
but I'm still wondering if there is another and better way to do that

카테고리

Help CenterFile Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by