The number of digits inside hex numbers should be a multiple of 2

Share your ideas as to how the documentation can be improved.
john_c
Posts: 474
Joined: 05 May 2017, 13:19

The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 05:47

This is a minor issue.

I was told that the number of digits inside a hex number should be represented as a multiple of 2.
https://simple.wikipedia.org/wiki/Hexadecimal:
In computer jargon four bits make a nibble. A nibble is one hexadecimal digit, written using a symbol 0-9 or A-F. Two nibbles make a byte (8 bits).

https://softwareengineering.stackexchange.com/a/415198:
You write 0A, not A or 00A even though they are technically the same number.
Both 0xA and 0x0A are representations of decimal 10, but only the second notation (0x0A) is really correct (at my personal opinion, of course).

Documentation uses the first one (0xA). It may be easier to eyes, but on the other hand it may be considered as inaccurate.

Some examples:

Code: Select all

; https://www.autohotkey.com/docs/commands/PostMessage.htm
SendMessage, 0xC, 0, &MyVar, ClassNN, WinTitle  ; 0XC is WM_SETTEXT

; would be better:
SendMessage, 0x0C, 0, &MyVar, ClassNN, WinTitle  ; 0x0C is WM_SETTEXT

Code: Select all

; https://www.autohotkey.com/docs/commands/DllCall.htm:
FILE_SHARE_WRITE := 0x2

; would be better:
FILE_SHARE_WRITE := 0x02
User avatar
boiler
Posts: 6094
Joined: 21 Dec 2014, 02:44

Re: The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 10:26

In my opinion, you are over-generalizing a convention specifically applying to representing bytes, and representing a number by a single hex digit is fine.
john_c wrote:
https://simple.wikipedia.org/wiki/Hexadecimal:
In computer jargon four bits make a nibble. A nibble is one hexadecimal digit, written using a symbol 0-9 or A-F. Two nibbles make a byte (8 bits).

https://softwareengineering.stackexchange.com/a/415198:
You write 0A, not A or 00A even though they are technically the same number.
Both references have to do specifically with bytes. The quote from the second reference is actually preceded by a sentence giving its full context:
So if you write a byte value as hex, you always write 2 hex digits, even if the number is below 16. You write 0A, not A or 00A even though they are technically the same number.
In fact, the next reply, which has the same number of up-votes in case you're using that to ascribe authority, says:
The "appropriate" format is typically context dependent...But in general, it's not much different than decimal numbers.


john_c wrote: Documentation uses the first one (0xA). It may be easier to eyes, but on the other hand it may be considered as inaccurate.
Accuracy is definitely not affected by leading zeroes.

john_c wrote: Some examples:

Code: Select all

; https://www.autohotkey.com/docs/commands/PostMessage.htm
SendMessage, 0xC, 0, &MyVar, ClassNN, WinTitle  ; 0XC is WM_SETTEXT

; would be better:
SendMessage, 0x0C, 0, &MyVar, ClassNN, WinTitle  ; 0x0C is WM_SETTEXT

Code: Select all

; https://www.autohotkey.com/docs/commands/DllCall.htm:
FILE_SHARE_WRITE := 0x2

; would be better:
FILE_SHARE_WRITE := 0x02
Those examples are values of constants. There really isn't a reason to say that a constant should be represented as a byte. In many languages in which they're used, they're probably used as an int (integer) type, which is typically 4 bytes. So it might make as much sense to argue that the value should be represented by 4 bytes (0x0000000A), although I wouldn't want to see them shown that way either.
just me
Posts: 7284
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 11:20

CreateFile:
FILE_SHARE_WRITE
0x00000002

winnt.h

Code: Select all

#define FILE_SHARE_WRITE                0x00000002
User avatar
boiler
Posts: 6094
Joined: 21 Dec 2014, 02:44

Re: The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 11:31

Also on that same page from Microsoft:
FILE_ATTRIBUTE_HIDDEN
2 (0x2)
...not 0x02
just me
Posts: 7284
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 16:06

winnt.h

Code: Select all

#define FILE_ATTRIBUTE_HIDDEN               0x00000002
;)
User avatar
boiler
Posts: 6094
Joined: 21 Dec 2014, 02:44

Re: The number of digits inside hex numbers should be a multiple of 2

26 Aug 2020, 16:15

Which I believe shows that Microsoft believes that 0x2 is fine for their documentation even while using leading zeros in their code. :)
User avatar
jNizM
Posts: 2662
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: The number of digits inside hex numbers should be a multiple of 2

28 Aug 2020, 03:45

Even Microsoft does not care about an unified system.

All from same header file

Code: Select all

#define FAIL_FAST_GENERATE_EXCEPTION_ADDRESS    0x1
#define FAIL_FAST_NO_HARD_ERROR_DLG             0x2

Code: Select all

#define COPY_FILE_FAIL_IF_EXISTS                0x00000001
#define COPY_FILE_RESTARTABLE                   0x00000002
#define COPY_FILE_OPEN_SOURCE_FOR_WRITE         0x00000004
#define COPY_FILE_ALLOW_DECRYPTED_DESTINATION   0x00000008

Code: Select all

#define FILE_TYPE_UNKNOWN   0x0000
#define FILE_TYPE_DISK      0x0001
#define FILE_TYPE_CHAR      0x0002
#define FILE_TYPE_PIPE      0x0003
#define FILE_TYPE_REMOTE    0x8000

Code: Select all

#define OF_READ             0x00000000
#define OF_WRITE            0x00000001
#define OF_READWRITE        0x00000002
#define OF_SHARE_COMPAT     0x00000000
#define OF_SHARE_EXCLUSIVE  0x00000010
#define OF_SHARE_DENY_WRITE 0x00000020
#define OF_SHARE_DENY_READ  0x00000030
#define OF_SHARE_DENY_NONE  0x00000040
#define OF_PARSE            0x00000100
#define OF_DELETE           0x00000200
#define OF_VERIFY           0x00000400
#define OF_CANCEL           0x00000800
#define OF_CREATE           0x00001000
#define OF_PROMPT           0x00002000
#define OF_EXIST            0x00004000
#define OF_REOPEN           0x00008000
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you

Return to “Suggestions on documentation improvements”

Who is online

Users browsing this forum: No registered users and 4 guests