Perché StrToInt ('X5') restituisce 5 in Delphi? X ha qualche notazione scientifica o qualcosa del genere? Ci sono altri caratteri che verranno convertiti anche in interi?Perché StrToInt ('X5') restituisce 5 in Delphi?
6
A
risposta
11
Non conoscendo Delphi, scommetto che la "X" fa in modo che la funzione assuma che il valore sia esadecimale. Dal momento che 0x5 == 5, sembra funzionare. Prova X10 e vedi se torni 16.
1
È una notazione esadecimale. Prova XF a vederlo restituire 15.
0
Probabilmente notazione hexadecimal.
La X indica che il numero che segue è esadecimale (0-9 + A-F).
11
In Delphi, valori esadecimali sono contrassegnati con $ prefisso:
a := $10; // => a = 16
Ma dal momento che in alcune altre lingue (ad esempio C) X viene utilizzato per la marcatura di valori esadecimali, funzione StrToInt supporta sia $ e prefissi X, in modo da entrambi i codici seguenti restituiscono 16:
a := StrToInt('x10'); // => a = 16
a := StrToInt('$10'); // => a = 16
Problemi correlati
- 1. In Delphi 5, può mai sollevare un'eccezione?
- 2. Perché python max ('a', 5) restituisce il valore stringa?
- 3. Perché {} + [] restituisce 0 in Javascript?
- 4. Perché questo avviso 5?
- 5. Laravel 5 restituisce datetime con fuso orario
- 6. Perché Math.round (0.49999999999999994) restituisce 1?
- 7. Come calcolare CRC 16 con polinomiale x16 + x12 + x5 + 1
- 8. Perché ISNUMERIC ('.') Restituisce 1?
- 9. Perché getHandler() restituisce null?
- 10. perché Files.probeContentType restituisce null
- 11. Perché Assembly.GetExecutingAssembly() restituisce null?
- 12. Perché Enum.Parse() restituisce l'oggetto?
- 13. Perché preg_match restituisce alcuni elementi vuoti?
- 14. non restituisce nulla. Perché?
- 15. Perché document.GetElementById restituisce null
- 16. Perché CMSampleBufferGetImageBuffer restituisce NULL
- 17. Possiamo chiamare .net (2.0) dll dall'applicazione Delphi 5
- 18. Perché map.erase restituisce l'iteratore?
- 19. Perché Parse.Config restituisce undefined?
- 20. Perché chrome.extension.getBackgroundPage() restituisce null?
- 21. Perché sys.getrefcount() restituisce 2?
- 22. Perché Array.to_s restituisce parentesi?
- 23. Perché IndexOf restituisce -1?
- 24. JavaScript: Perché [] + (- ~ {} - ~ {} - ~ {} - ~ {}) + (- ~ {} - ~ {}); restituisce "42"
- 25. Perché String.Equals restituisce false?
- 26. Perché AES_DECRYPT restituisce null?
- 27. Perché navigator.appCodeName restituisce Mozilla?
- 28. Perché innerHTML restituisce "indefinito"?
- 29. Perché HttpContext.Current.User.Identity.Name restituisce vuoto
- 30. Delphi 5 causa EAccessViolation quando manifest viene aggiunto come risorsa
F è 15, non 16. – Pesto