| | |
Binary constants???
![]() |
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
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.
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.
just see my example..only reference 

pascal Syntax (Toggle Plain Text)
Program Program001; Uses Crt; {just example...} Const A:Array[1..3]Of Record A:LongInt; B:Byte; End =((A:$E0349;B:$35) ,(A:$E0359;B:$30) ,(A:$E0389;B:$31)); {give the values in hex !!! } Var Ch:Char; index:Byte; Begin {main} ClrScr; {Just reference...} For index:=1 To 3 Do Begin Ch:=Char(A[index].B); {converts type !!! } WriteLn(ch); {just for results} End; {I hope,you got it!!!} ReadKey; End. {main} (*Created By FlamingClaw 2009.03.14*)
Last edited by FlamingClaw; Mar 14th, 2009 at 6:17 pm.
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
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.
•
•
•
•
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 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
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...
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...
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:
Hence, a large binary sequence can easily be represented with about a quarter of the characters in hexadecimal:
instead of
Hope this helps.
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)
0000b = $0 0001b = $1 ... 1001b = $9 1010b = $A 1011b = $B ... 1111b = $F
$4A9Finstead of
1000101010011111bHope this helps.
•
•
•
•
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:
Hence, a large binary sequence can easily be represented with about a quarter of the characters in hexadecimal:Pascal and Delphi Syntax (Toggle Plain Text)
0000b = $0 0001b = $1 ... 1001b = $9 1010b = $A 1011b = $B ... 1111b = $F
$4A9F
instead of
1000101010011111b
Hope this helps.
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...
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...
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
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.
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.
•
•
•
•
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.
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.
1. Don't tell clients everything you know.
![]() |
Similar Threads
- Display a number in binary (C#)
- error C2677: binary '==' : no global operator found (C++)
- fstream with structures loop help! (C++)
- representing binary values (C)
- Machine Constants in Javascript? (JavaScript / DHTML / AJAX)
- Pascal -> C++; Binary, convert? (C++)
- urgent i have only 24 hours (Assembly)
- how to call these functions? (C#)
- Ruby multithreading (Ruby)
- Need direction on how start this program (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: ReadProcessMemory HELL
- Next Thread: delphi conversion software
| Thread Tools | Search this Thread |






