00 Votes

Lazarus: Enter Binary Numbers using Zeros and Ones directly in the Code

Question by Guest | 2014-02-02 at 21:33

Currently, I am writing a program in which I need to perform some calculations. Because of the numbers and values ​​used, the easiest way for me would be to enter the values not as an integer but directly as a binary number.

So, I would like to enter the 1s and 0s such as the computer is calculating internally (for example "101001" + "100010") directly in my code.

Is there any way to do that? Some of my recent attempts were not crowned with any success, I only got compiler errors.

ReplyPositiveNegative
Avatar
0Best Answer0 Votes

Yes. This is possible without any problems. Numbers that are given in binary format are marked with a preceding %:

var
  k: integer;
begin
  k := 10 + %1010;
  // k has the value 20
end;

So, instead of the decimal number 10, you can also write %1010 and combine those binary values with integers. In the example above, we add the integer value 10 to the binary number 1010 and obtain 20 as a result.

For more information, check out the article about the input of binary numbers, hexadecimal numbers and integers in Lazarus, I have just written after you have brought me with your question to that idea. 
2014-02-03 at 16:46

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.