Solved

The symbol '$'???

Posted on 1998-07-28
20
315 Views
Last Modified: 2010-04-04
Hello all, How are y'all doin'? OK...Here is my question...

1)Can anyone explain what the symbol $ means, and how is it used...

For example I have a declaration like this:
var TempByte : Byte;
begin
  TempByte := $80;
...
end;
2)Can you tell me how to determine what's the value of that, and if there are any other
ways to use this symbol what are they?

Viktor Ivanov
0
Comment
Question by:viktornet
  • 9
  • 6
  • 3
  • +1
20 Comments
 

Expert Comment

by:buboi
ID: 1358923
'$' indicates a hexadecimal numeral, and it also be used in the compiler directive.
for example, {$R *.dfm}
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358924
OK tell me something more specific, for example what number is represented by the value $80... I tried this to find out... Edit1.text := IntToStr($80);...but I'm not sure if that's the right value..
And why use hexadecimal instead of a decimal value like 128 or somethin' else... Can you tell me something more specific and I will accept your answer...Thanx..

Viktor Ivanov
0
 

Accepted Solution

by:
buboi earned 0 total points
ID: 1358925
for example,
$80 is equal 128,
$f  is equal 15,
$ff is equal 255,
if you want to use some API directly, maybe you need pass some parameters using hex numral, use '$' and hex numral is clear, we needn't tranfer these to dec numrals.


0
 
LVL 10

Author Comment

by:viktornet
ID: 1358926
OK, I'll give you the points... :-), even though I'm still not sure at least you tried, thanx...
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358927
OK, I'll give you the points... :-), even though I'm still not sure at least you tried, thanx...
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1358928
Hi,
Just a comment for clarification:
Hexadecimal numbers use 16 as a base while "normal" decimal numbers use 10. These are commonly used by programmers since they are easily converted to/from binary numbers used by the hardware.
Binary "digits" are: 0,1
Decimal "digits" are: 0,1,2,3,4,5,6,7,8,9
Hexadecimal "digits" are: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f

That makes:
Dec: - Hex:
  0 -   0
  1 -   1
  2 -   2
  3 -   3
.
  8 -   8
  9 -   9
 10 -   a
 11 -   b
 12 -   c
 13 -   d
 14 -   e
 15 -   f
 16 -  10
 17 -  11
.
 31 -  1e
 32 -  20
.
255 -  ff
256 - 100

Bin: - Hex:

00000001 - 01
00000010 - 02
00000011 - 03
00001111 - 0f
00010000 - 10

(do you see the 4:1 connection?)

In Pascal (Delphi) the compiler has to know when the programmer is using decimal representation of the numbers and when he/she uses hexadecimal representation. To do this, the hexadecimal numbers are prefixed with "$". In C/C++ the equivalent is "0x":

Pascal (Delphi):  "$fe"
C/C++          :  "0xfe"

As Buboi is mentioning, the "$" also represents a compiler directive. These have nothing to do with the hexadecimal representation.

A tip: To convert hexadecimal numbers to and from strings use:
  MyHexStr := IntToHex( 254, 2 ); // 254 => 'fe'
  MyInt := StrToInt( '$' + MyHexStr ); // MyHexStr = 'fe' => 254

Hope this doesn't make things worse, but simplify the matter to you.

/// John

0
 
LVL 10

Author Comment

by:viktornet
ID: 1358929
Oh, hello! I seem to have forgotten to check the box and haven't recieved the message. Thanks a lot, and that's exactly what I was looking for. Thanks John. I've got a question. Ok let's say I've got 134. without using any calcs, or programming what do you need to do in order to convert the decimal value to hexadecimal. I think first I need to convert it to a binary and then get it's value into hexadecimal. Is that the way it is done or am I missing something? Thanx again. If I hadn't accepted the answer I would've given the points to you.

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358930
i just don't believe this.

vik - pleez tell me that u're takin' the mickey outta us!

Black Death.
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358931
What???

Never mind, forget it....
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358932
I ain't taking the mickey outta anyone! if you wanna get points just tell me and I'll be happy to give you some... Alright ...

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358933
heey vik.
calm down.
u know i ain't hot 4 points.
(i never answered a q, just commented)

what i meant is:
was that a real q, or just a joke?

i didn't mean 2 attack u - 4 heaven's sake!

very sorry if u got that wrong.

Black Death.

0
 
LVL 10

Author Comment

by:viktornet
ID: 1358934
It was a question some time ago, but I couldn't get an answer so accepted that guys answer. Anyway, John answered everythin' I needed to know, so I'm really thankful... just didn't get a small part of it, but anyway...who cares..  Talk to ya later

//Vik
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358935
ok.
i'm afraid i must have sounded stuck-up 2 ya.
sorry again.

til later & have a nice day,

Black Death.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358936
ok.
i'm afraid i must have sounded stuck-up 2 ya.
sorry again.

til later & have a nice day,

Black Death.
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358937
Thanx . U 2

Regards,
Viktor Ivanov
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1358938
Hi Viktor,
What is it you really lack from my comment?
In the processor there is no difference between a decimal and a hexadecimal number since all is done binary.

If you want to convert 134 to hex "by hand", then do this:

1. Divide number by 16:
  134 / 16 => 8.375
2. Take fractional part of the answer times 16 to get first number.
This is called MODULO (134 mod 16):
  0.375 * 16 => 6 (put this farthest to the right)
3. Repeat the above two steps with the remaining integer part of the answer, until it is 0(zero):
  8 / 16 => 0.5
  0.5 * 16 => 8

This gives the hexadecimal number 86h.

---

To make it tougher; 51966 in hex is:
  51966 / 16 => 3247.875
  0.875 * 16 => 14 => E (hexadecimal representation of 14, remember?, put this farthest to the right)

  3247 / 16 => 202.9375
  0.9375 * 16 => 15 => F

  202 / 16 => 12.625
  0.625 * 16 => 10 => A

  12 / 16 => 0.75
  0.75 * 16 => 12 => C

That makes C A F E, CAFEh, which is a nice place to go when the coffe provided at work tastes too bad. Lots of nice other "things" there too, if you know what I mean!? >;->

And, BlackDeath...; could you please stop using this strange english syntax? I'm "0" as cool as "U" so I can "0" understand what "U" "R" trying "2" say... ;|

/// John
0
 
LVL 10

Author Comment

by:viktornet
ID: 1358939
Hello John! Thanks.Now everything is clear. Finally understood how to convert one to another by hand. Once again thanks, and take care ;)

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358940
sure, john - no problem.

it's just a bad habit from former times.
i'll try and have an eye on it.
but don't be angry when one or the other howler slips in, ok?

regards,

Black Death.


0
 
LVL 4

Expert Comment

by:erajoj
ID: 1358941
No problem!
I'm not that stingy. Just thinking about all those with problems reading the marvelous english language. They're supposed to benefit from this too, right?

/// John
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1358942
right you are
bye,
Black Death.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now