Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, bigsmack, 1 invisible), 1,341 guests, and 14 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19057 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dezimalzahl in Binärzahl umwandel #434672
12/23/13 14:36
12/23/13 14:36
Joined: Feb 2006
Posts: 212
Germany
Icke Offline OP
Member
Icke  Offline OP
Member

Joined: Feb 2006
Posts: 212
Germany
Hallo ihr da draussen,
Hab mal wieder ne blöde Frage.
Gibt es in LC schon eine einfache Funktion mit der ich Dezimalzahlen in Binärzahlen umwandeln kann bzw. in einen Biärwert.
Der Hintergrund ist folgender:
Ich habe mir eine Externe Spannungsversorgung(0-24V) gebaut die ich über den Paralellport ansteuere.
Wenn ich z.B. 4,5V ausgeben möcht muss hierzu den wert von portout auf 11 setzen.
also portout(888,11);
Dies entspricht binär 1011.
zu stande kommt dieser Wert in dem ich von der gesamtspannung, 24V, die 4,5V abziehe.
also 19.5V.
In dieser 19,5 stecht 1x die 8(Bit4) = 1.5, 0x die 4(Bit3), 1x die 2(Bit2) = 6 und 1x die 1(Bit1) = 12.
Also rechnerich
19,5 - 12 Rest 7,5 1x
7,5 - 6 Rest 1,5 1x
1,5 - 3 Rest X 0x
1,5 - 1,5 Rest 0 1x
Ich hoffe ich konnte mein Problem verständlich machen und hoffe auf eure Unterstützung.

Re: Dezimalzahl in Binärzahl umwandel [Re: Icke] #434673
12/23/13 14:42
12/23/13 14:42
Joined: Feb 2006
Posts: 212
Germany
Icke Offline OP
Member
Icke  Offline OP
Member

Joined: Feb 2006
Posts: 212
Germany
Hab mir gerade meinen Text noch mal durhgelesen und ihne selbst nicht so richtig verstanden.
1 entspricht 12V
2 entspricht 6V
4 entspricht 3V
8 entspricht 1,5V
um 4,5V einzustellen muss ich 24 - (12V - 6V - 1,5V) rechnen also 1+2+8 für portout.

Re: Dezimalzahl in Binärzahl umwandel [Re: Icke] #434674
12/23/13 15:47
12/23/13 15:47
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Führe mal folgenden Code aus:

Code:
void main()
{
	int i;
	var wert = 987;
	fps_max = 60;
	while(1)
	{
		for(i = 0; i < 32; i++)
		{
			DEBUG_VAR(!!(wert & (1<<i)),20+i*20);
		}
		wait(1);
	}
}


Du siehst dann alle Bits von "wert" untereinander aufgelistet, wobei "!!" aus nicht-0 einfach 1 macht (ohne "!!" stünden dort dann die entsprechenden Zweierpotenzen). Hilft dir das weiter?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Dezimalzahl in Binärzahl umwandel [Re: Superku] #434686
12/24/13 01:33
12/24/13 01:33
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Ich hatte schon ein code hier gepostet.

Hier noch einmal mit kleine Änderung und hoffe das es weiter hilft:

Code:
#include <default.c>

STRING *sBin = ""; 

void Dec2Bin(int n) {
	if (!n) {return;
		}else{
		Dec2Bin(n/2);
		str_cat_num(sBin,"%.0f",n%2);
	}
}

void main() {
	int iDec = 11;
	Dec2Bin(iDec);
	printf("%s", _chr(sBin));
}



Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1