Sep 18, 2002 #1 bregoty Programmer Sep 18, 2002 1 US hi, i have a doubt. i need to write a 'c' program for multiplication of two 4-bit binary numbers. plz help me in this regard. thank u, Bye -Balaji
hi, i have a doubt. i need to write a 'c' program for multiplication of two 4-bit binary numbers. plz help me in this regard. thank u, Bye -Balaji
Sep 19, 2002 #2 Zyrenthian Programmer Mar 30, 2001 1,440 US well, the easiest way to do it would be to use bit fields inside a struct struct fourBitValues { unsigned x: 4; unsigned y: 4; }; fourBitValues fbv; fbv.x = 12; fbv.y = 4; /* multiply fbv.x and fbv.y */ You may want some verification such as if(inputValue1 <= 0xF && inputValue2 <= 0xF) { // valid input } else { // invalid } That should do it for you Matt Upvote 0 Downvote
well, the easiest way to do it would be to use bit fields inside a struct struct fourBitValues { unsigned x: 4; unsigned y: 4; }; fourBitValues fbv; fbv.x = 12; fbv.y = 4; /* multiply fbv.x and fbv.y */ You may want some verification such as if(inputValue1 <= 0xF && inputValue2 <= 0xF) { // valid input } else { // invalid } That should do it for you Matt