Matrice [C / C++]
Moderatore:
Paolino
0
voti
Salve a tutti, avrei la necessità di fare una tabella della verità a 3 bit (8 combinazioni) però vorrei usare meno ram possibile... e dividere bit per bit come potrei farlo?
-

daniele1996
610 3 8 11 - Sostenitore

- Messaggi: 1554
- Iscritto il: 29 ago 2011, 11:29
1
voti
Non ho capito cosa devi fare.
"La follia sta nel fare sempre la stessa cosa aspettandosi risultati diversi".
"Parla soltanto quando sei sicuro che quello che dirai è più bello del silenzio".
Rispondere è cortesia, ma lasciare l'ultima parola ai cretini è arte.
"Parla soltanto quando sei sicuro che quello che dirai è più bello del silenzio".
Rispondere è cortesia, ma lasciare l'ultima parola ai cretini è arte.
-

TardoFreak
73,9k 8 12 13 - -EY Legend-

- Messaggi: 15754
- Iscritto il: 16 dic 2009, 11:10
- Località: Torino - 3° pianeta del Sistema Solare
0
voti
Oddio scusami sono stato troppo vago
hai presente la tabella della verità:
0 0 0
0 0 1
0 1 0
1 0 0
1 0 1
1 1 0
1 1 1
ecco devo rappresentare questa cosa nella Ram
hai presente la tabella della verità:
0 0 0
0 0 1
0 1 0
1 0 0
1 0 1
1 1 0
1 1 1
ecco devo rappresentare questa cosa nella Ram
-

daniele1996
610 3 8 11 - Sostenitore

- Messaggi: 1554
- Iscritto il: 29 ago 2011, 11:29
2
voti
Ma perché avete tutti questa abitudine di scrivere C/C++ come se fossero lo stesso linguaggio o come se l'uso dell'uno o dell'altro portasse alla stessa soluzione?
C e C++ sono due linguaggi differenti. In quale linguaggio devi programmare tu?
C e C++ sono due linguaggi differenti. In quale linguaggio devi programmare tu?
It's a sin to write
instead of
(Anonimo).
...'cos you know that
ain't
, right?
You won't get a sexy tan if you write
in lieu of
.
Take a log for a fireplace, but don't take
for
arithm.
instead of
(Anonimo)....'cos you know that
ain't
, right?You won't get a sexy tan if you write
in lieu of
.Take a log for a fireplace, but don't take
for
arithm.-

DirtyDeeds
55,9k 7 11 13 - G.Master EY

- Messaggi: 7012
- Iscritto il: 13 apr 2010, 16:13
- Località: Somewhere in nowhere
0
voti
C++ però ho scritto anche C perché non so che compilatore usa Dev c++ ....
-

daniele1996
610 3 8 11 - Sostenitore

- Messaggi: 1554
- Iscritto il: 29 ago 2011, 11:29
0
voti
daniele1996 ha scritto:usa Dev c++ ....
Dev C++ è un IDE che usa Mingw come compilatore, il compilatore gcc portato sotto Windows. Il fatto che compili per C o C++ dipende da cosa gli dici tu di fare, non è che prenda lui l'iniziativa.
It's a sin to write
instead of
(Anonimo).
...'cos you know that
ain't
, right?
You won't get a sexy tan if you write
in lieu of
.
Take a log for a fireplace, but don't take
for
arithm.
instead of
(Anonimo)....'cos you know that
ain't
, right?You won't get a sexy tan if you write
in lieu of
.Take a log for a fireplace, but don't take
for
arithm.-

DirtyDeeds
55,9k 7 11 13 - G.Master EY

- Messaggi: 7012
- Iscritto il: 13 apr 2010, 16:13
- Località: Somewhere in nowhere
0
voti
Non lo so, io conosco il C, non il C++.
It's a sin to write
instead of
(Anonimo).
...'cos you know that
ain't
, right?
You won't get a sexy tan if you write
in lieu of
.
Take a log for a fireplace, but don't take
for
arithm.
instead of
(Anonimo)....'cos you know that
ain't
, right?You won't get a sexy tan if you write
in lieu of
.Take a log for a fireplace, but don't take
for
arithm.-

DirtyDeeds
55,9k 7 11 13 - G.Master EY

- Messaggi: 7012
- Iscritto il: 13 apr 2010, 16:13
- Località: Somewhere in nowhere
0
voti
- Codice: Seleziona tutto
#pragma pack(push, 1)
typedef struct
{
unsigned char b0 : 1;
unsigned char b1 : 1;
unsigned char b2 : 1;
} yourMatrix_t;
#pragma pack(pop)
Sia per C che per C++
1 byte, meno non puoi. I singoli bit rappresntano gli ingressi della tua tabella.
Si avvicina a ciò che ti serve?
Anyone who has never made a mistake has never tried anything new
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
-

Shockwaver
770 1 5 11 - Expert

- Messaggi: 859
- Iscritto il: 3 mar 2010, 18:56
0
voti
Se poi hai bisogno di una tabella completamente strutturata e popolata puoi fare così (sparo perché nn so che devi fare)
3 byte di allocazione, 4 di utilizzo per via dell'allineameno della RAM.
- Codice: Seleziona tutto
#pragma pack(push, 1)
typedef union
{
unsigned char Val : 3;
struct
{
unsigned char b0 : 1;
unsigned char b1 : 1;
unsigned char b2 : 1;
} bits;
} TableEntry_t;
typedef union
{
unsigned int Val : 24;
struct
{
unsigned char FFF : 3;
unsigned char FFT : 3;
unsigned char FTF : 3;
unsigned char FTT : 3;
unsigned char TFF : 3;
unsigned char TFT : 3;
unsigned char TTF : 3;
unsigned char TTT : 3;
} Entries;
} TruthTable_t;
#pragma pack(pop)
int main(int argc, char **argv, char **envp)
{
TruthTable_t TruthTable = {.Val = 0xFAC688}; /* Calcolato al volo, meglio controllare */
TableEntry_t Entry;
Entry.Val = TruthTable.TTF;
[...]
return EXIT_SUCCESS;
}
3 byte di allocazione, 4 di utilizzo per via dell'allineameno della RAM.
Ultima modifica di
Shockwaver il 19 apr 2014, 17:12, modificato 1 volta in totale.
Anyone who has never made a mistake has never tried anything new
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
Two things are infinite: universe and human stupidity, and I'm not sure about the former
You did not really understand something unless you can explain it to your grandmother
A. Einstein
-

Shockwaver
770 1 5 11 - Expert

- Messaggi: 859
- Iscritto il: 3 mar 2010, 18:56
Torna a Firmware e programmazione
Chi c’è in linea
Visitano il forum: Nessuno e 4 ospiti

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)