Vedere il titolo. Il valore restituito è 32 bit, giusto? Perché non restituire un int?Perché java.util.zip.CRC32.getValue() restituisce un valore long, non un int?
8
A
risposta
9
Perché se restituisse un int, metà del CRC sarebbe negativo. L'aspettativa è che un CRC a 32 bit non sia firmato, vale a dire 0,4294967295, che non può essere rappresentato in un int.
2
java.util.zip.CRC32
implementa l'interfaccia Checksum
, che richiede un tipo long
cambio getValue()
, richiedendo così un long
per un checksum a 32 bit; i 32 bit superiori dell'output sono quasi definitivamente 0.
Problemi correlati
- 1. Perché Int64.MaxValue restituisce un valore Long?
- 2. Perché Math.Round non restituisce un int?
- 3. Perché operator ++ restituisce un valore non const?
- 4. Perché InputStream # read() restituisce un int e non un byte?
- 5. C++: long long int vs long int vs int64_t
- 6. int to long assignment
- 7. unsigned long long int pow
- 8. Perché non scriviamo int x = printf ("testo"); poiché l'istruzione printf() restituisce un valore intero ogni volta?
- 9. C# string.GetHashCode() restituisce un risultato non int.
- 10. Come convertire un long in int in Java vs. swift?
- 11. Android - Perché onItemLongClick (...) restituisce un valore booleano?
- 12. Perché questa funzione Perl restituisce un valore?
- 13. Il GCC supporta long long int?
- 14. Perché Math.ceil restituisce un doppio?
- 15. javax.servlet.HttpServletRequest.getContentLength() restituisce solo int
- 16. Perché non .getPropertyValue() restituisce un valore per la proprietà "borderRadius"?
- 17. Perché un ritorno non è definito ma console.log restituisce un int?
- 18. Can scala.util.Random.nextInt(): Int occasionalmente restituisce un valore negativo?
- 19. assegnando un valore nullo per un int
- 20. perché math.Ceiling (double a) non restituisce direttamente int?
- 21. "+ =" operatore e int long use
- 22. Perché int = int * double restituisce un errore e int * = double no (in Java)?
- 23. Perché questo OR bit a bit restituisce null su un valore int nullo?
- 24. Perché floor non restituisce un intero?
- 25. Perché numeric_limits :: min restituisce un valore negativo per int ma valori positivi per float/double?
- 26. Perché l'operatore di incremento post non funziona su un metodo che restituisce un int?
- 27. Come `({...})` restituisce un valore?
- 28. perché 1e400 non è un int?
- 29. Meteor.methods restituisce un valore non definito
- 30. funzione anonima non restituisce sempre un valore
Mark, grazie per la risposta. Ho un seguito: sto leggendo e scrivendo file i cui ultimi byte sono un CRC di tutti i byte precedenti. Il CRC deve essere contenuto in 4 byte. Quindi non posso ignorare i 4 byte superiori del CRC lungo, posso? Avrei bisogno di convertire la rappresentazione lunga e una "non firmata", in primo luogo, giusto? – Steveo
Per definizione, un CRC a 32 bit si adatta ai quattro byte bassi del lungo. Non c'è alcun tipo di 32 bit senza segno in Java. –