Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

4-bit binary numbers multiplication

Status
Not open for further replies.

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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top