A Little help with Bits...

P

p3tris

help me with this problem. I have stated this:

typedef unsigned short WORD;
struct cube {
WORD t;
WORD f;
};
typedef struct cube CUBE;
CUBE cubes[MAX_VARS+1][MAX_CUBES];

And i have to make a procedure that will read from the keyboard
binaries and activate the .t or .f of cubes array accordingly.
Will activate 1 in .t if if we have 1 in that place, 1 in .f if we have
0 in that place and 0 in both places if that place has a '-'.

EXAMPLE:
IF I INSERT P= 1010001 WILL MAKE:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0101110)

If i put P = 101-001 will make:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0100110)

Please some help would be REALLY appreciated. You can contact me at:

p3tris (at) gmail (dot) com
 
T

Tomás

posted:
help me with this problem. I have stated this:

typedef unsigned short WORD;
struct cube {
WORD t;
WORD f;
};
typedef struct cube CUBE;
CUBE cubes[MAX_VARS+1][MAX_CUBES];


Cubes have three dimensions.

And i have to make a procedure that will read from the keyboard
binaries and activate the .t or .f of cubes array accordingly.
Will activate 1 in .t if if we have 1 in that place, 1 in .f if we have
0 in that place and 0 in both places if that place has a '-'.


Very poorly worded -- I don't know what you're saying.

What do you mean by "read binaries from the keyboard"? What do you mean by
"activate the .t or .f"?

EXAMPLE:
IF I INSERT P= 1010001 WILL MAKE:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0101110)

If i put P = 101-001 will make:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0100110)

Please some help would be REALLY appreciated. You can contact me at:

p3tris (at) gmail (dot) com


Is that the billing address?


-Tomás
 
O

osmium

typedef unsigned short WORD;
struct cube {
WORD t;
WORD f;
};
typedef struct cube CUBE;
CUBE cubes[MAX_VARS+1][MAX_CUBES];

And i have to make a procedure that will read from the keyboard
binaries and activate the .t or .f of cubes array accordingly.
Will activate 1 in .t if if we have 1 in that place, 1 in .f if we have
0 in that place and 0 in both places if that place has a '-'.

EXAMPLE:
IF I INSERT P= 1010001 WILL MAKE:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0101110)

If i put P = 101-001 will make:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0100110)

You have embedded a fairly simple problem in a lot of non-issues. Including
a two-dimensional array that has nothing to do with your apparent problem.
I think the word you want for "activate" is "set". In C, the word for
procedure is function. You can not read binary from a keyboard, what you
can do is read characters and convert the characters into binary. Defer the
'-' problem at first, if there is a hyphen in the input, replace it with a
"don't care", either 1 or 0. Having done that (and ignoring the seven bit
situation), if k contains the binary input, then,

char a, b;

a = k does the .t thing
b = ~k. does the .f thing. (~ is one's complement)

Then handle the hyphen. You can force a 0 by selective use of the &
operator, note that 1 & 0 = 0 and 0 & 0 is also 0. So the right bit is
often called a "mask".

The word cube seems like an improbable name for a thing with only two
constituent elements.

I suggest you get these basics working and then and only then incorporating
what you have into an array.
 
W

Walter Roberson

And i have to make a procedure that will read from the keyboard
binaries and activate the .t or .f of cubes array accordingly.
Will activate 1 in .t if if we have 1 in that place, 1 in .f if we have
0 in that place and 0 in both places if that place has a '-'.

When you say "binaries", do you mean "The text representation of
a binary string" ?

Your input strings are not binary, by the way: they are trinary,
since each position can have 3 states.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,515
Latest member
Harvey7327

Latest Threads

Top