Binary constants???

Reply

Join Date: Oct 2008
Posts: 35
Reputation: m610 is an unknown quantity at this point 
Solved Threads: 1
m610 m610 is offline Offline
Light Poster

Binary constants???

 
0
  #1
Mar 13th, 2009
I guess I should be embarrassed to ask this, but Help seems to be misleading to me, so it's not my fault.

I'd like to enter a series of binary numbers in a component I am working on. Delphi's Help (see below) says all I need to do is add a "b" to my number, but I get an "undeclared identifier..." error, for code like:

br2400= 00000011b; // 2400 baud

Yea, I could use hex, but in this case it is easier to make the numbers look like those in the manual for the device I am programming.

Numeric constants
Numeric constants must be integers, and their values must be between –2,147,483,648 and 4,294,967,295.
By default, numeric constants use decimal notation, but the built-in assembler also supports binary, octal, and hexadecimal. Binary notation is selected by writing a B after the number, octal notation by writing an O after the number, and hexadecimal notation by writing an H after the number or a $ before the number.
Numeric constants must start with one of the digits 0 through 9 or the $ character. When you write a hexadecimal constant using the H suffix, an extra zero is required in front of the number if the first significant digit is one of the digits A through F. For example, 0BAD4H and $BAD4 are hexadecimal constants, but BAD4H is an identifier because it starts with a letter.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Binary constants???

 
0
  #2
Mar 14th, 2009
just see my example..only reference
  1.  
  2. Program Program001;
  3. Uses Crt;
  4. {just example...}
  5. Const A:Array[1..3]Of Record
  6. A:LongInt;
  7. B:Byte;
  8. End =((A:$E0349;B:$35)
  9. ,(A:$E0359;B:$30)
  10. ,(A:$E0389;B:$31));
  11. {give the values in hex !!! }
  12. Var Ch:Char;
  13. index:Byte;
  14.  
  15. Begin {main}
  16. ClrScr;
  17. {Just reference...}
  18. For index:=1 To 3 Do
  19. Begin
  20. Ch:=Char(A[index].B); {converts type !!! }
  21. WriteLn(ch); {just for results}
  22. End;
  23. {I hope,you got it!!!}
  24. ReadKey;
  25. End. {main}
  26.  
  27. (*Created By FlamingClaw 2009.03.14*)
Last edited by FlamingClaw; Mar 14th, 2009 at 6:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: m610 is an unknown quantity at this point 
Solved Threads: 1
m610 m610 is offline Offline
Light Poster

Re: Binary constants???

 
0
  #3
Mar 14th, 2009
Thanks, but I see only hex, no binary, in your example.

I'd like to do something like MyConst = 10101010b

Delphi-Help says the "b" should take care of the binary declaration.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Binary constants???

 
0
  #4
Mar 14th, 2009
Ok...I understand that you have binary digits but what if you use hex insted of binary:
if you write
MyConst = 10101010b this is same with $A7 or 0A7h,got it?
167 in decimal
The processor will understand both of them.
'B' just notation!!! 2
'H' just notation!!! 16
'O' just notation!!! 8
Last edited by FlamingClaw; Mar 14th, 2009 at 7:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Binary constants???

 
0
  #5
Mar 14th, 2009
Originally Posted by FlamingClaw View Post
Ok...I understand that you have binary digits but what if you use hex insted of binary:
if you write
MyConst = 10101010b this is same with $A7 or 0A7h,got it?
167 in decimal
The processor will understand both of them.
'B' just notation!!! 2
'H' just notation!!! 16
'O' just notation!!! 8
I say USE Hex Numbers!!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Binary constants???

 
0
  #6
Mar 31st, 2009
I found a page where they show some interest about your problem
There they write that there are non-standard special symbols....
p:=2#10011;{ base 2}
There is only one problem with that ,the Turbo Pascal 7.0 do not recognize it,and when I try the Dev Pascal then same results....
They write that Pascal 4.2.......
http://web.mit.edu/sunsoft_v5.1/www/...x.doc.html#202
Last edited by FlamingClaw; Mar 31st, 2009 at 3:46 am. Reason: missing data
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Binary constants???

 
0
  #7
Apr 1st, 2009
BP variants don't accept binary numbers.
Assemblers accept binary numbers.
Since Delphi has a built-in assembler, you can use binary numbers with the assembler -- but not in the normal Pascal code.

FlamingClaw -- that page is for a Pascal compiler which supports ISO-10206 (Extended Pascal), which is largely incompatible with Delphi variants.

m610 -- Just use hexadecimal. It is much easier on the eyes than binary anyway:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. 0000b = $0
  2. 0001b = $1
  3. ...
  4. 1001b = $9
  5. 1010b = $A
  6. 1011b = $B
  7. ...
  8. 1111b = $F
Hence, a large binary sequence can easily be represented with about a quarter of the characters in hexadecimal:
$4A9F
instead of
1000101010011111b

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Binary constants???

 
0
  #8
Apr 1st, 2009
Originally Posted by Duoas View Post
FlamingClaw -- that page is for a Pascal compiler which supports ISO-10206 (Extended Pascal), which is largely incompatible with Delphi variants.

m610 -- Just use hexadecimal. It is much easier on the eyes than binary anyway:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. 0000b = $0
  2. 0001b = $1
  3. ...
  4. 1001b = $9
  5. 1010b = $A
  6. 1011b = $B
  7. ...
  8. 1111b = $F
Hence, a large binary sequence can easily be represented with about a quarter of the characters in hexadecimal:
$4A9F
instead of
1000101010011111b

Hope this helps.
Ok Duoas I understand you,and you're right.In the beginning of that thread I mentioned that he 'd use hex numbers instead of binary.....
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: m610 is an unknown quantity at this point 
Solved Threads: 1
m610 m610 is offline Offline
Light Poster

Re: Binary constants???

 
0
  #9
Apr 1st, 2009
The reason I wanted to use binary is because the hardware I'm sending codes to describes many of the commands and the arguments they use in terms of bits set or cleared. It would be easier for me to translate what their manual says to my code if I stayed with binary.

I've pushed ahead and done most of the job already using hex, but the more interesting part of my question, I think, was that Help in Delphi 6 says I can use binary numbers, but then I get errors when I do it.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: weinelb is an unknown quantity at this point 
Solved Threads: 0
weinelb's Avatar
weinelb weinelb is offline Offline
Newbie Poster

Re: Binary constants???

 
0
  #10
May 12th, 2009
Originally Posted by m610 View Post
I guess I should be embarrassed to ask this, but Help seems to be misleading to me, so it's not my fault.
. . .
Yea, I could use hex, but in this case it is easier to make the numbers look like those in the manual for the device I am programming.
m610: Unfortunately, your confusion stems from the fact that the "Numeric Constants" section you cite says "but the built-in assembler also supports binary..." and, as Duoas said: "you can use binary numbers with the assembler -- but not in the normal Pascal code."

In the past when I had to create a Delphi program with a UI that supported binary notation for engineers my solution was a simple TBinary class descended from TObject. It included "ValueAsXxxx" properties (where Xxxx was "Byte", "Halfword", "Word", "DWord", etc.) and "DisplayXxxx" properties which were strings intended for the UI output and input. It also had methods to extract or set particular bits within a value using starting bit number, bit field width and a "display" string; e.g. "procedure Extract(Start, Width: integer; AValue: string; var Extracted: TBinary);", but there were also similar methods that used a UI string mask instead of start bit and width numbers. Internally the object only had one property value ("fValue: Int64;") and all of the other forms for both values and display strings were derived from, or affected, that "private" property value.

Investing time in creating a unit to implement such a class tailored to UI requirements actually saves time overall and greatly simplifies application logic. All of the shifts, and's, or's and xor's are confined to the class' methods -- rather than scattered about the program's event handlers. And, once the class is debugged, it just works...
There are two rules for success in consultancy:
1. Don't tell clients everything you know.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC