Wednesday, December 2, 2009

Apa Itu Hex?

Apakah Hex?

Para notasi heksadesimal hampir secara universal digunakan dalam perkomputeran - dan bukan tanpa alasan. Ada enam belas digit hex - 0 hingga 9, dan A hingga F (yang sesuai dengan nilai-nilai perpuluhan 10-15), dan masing-masing mewakili digit hex tepat empat bit. Tepat dua digit heksadesimal mewakili satu byte, yang boleh mempunyai nilai dari 00 hingga FF (iaitu 0-255 perpuluhan). Dalam rangka untuk menemukan nilai hex multi-byte objek, anda akan menyatukan para byte, misalnya, byte FE 58 A4 1B merupakan nilai byte empat 58A41BFE (atau FE1BA458 bila komputer menggunakan jujukan sebaliknya).

Tapi mengapa heksadesimal? Tak bisakah kita hanya menggunakan nombor perpuluhan tua yang baik? Yah, mereka akan baik-baik saja untuk komputer perpuluhan, tetapi kebanyakan komputer kontemporari binari dan bekerja pada bit dan byte. Sebuah angka perpuluhan mewakili sekitar 3,3 bit, dan ini membuat aritmatika terlalu rumit. Mari kita asumsikan kita memiliki dua byte dengan nilai perpuluhan 243 dan 78. Apa yang akan menjadi nilai byte dua kata? 24.378? Tidak, kaedah ini bekerja dengan digit heksadesimal sahaja. Untuk menemukan nilai perpuluhan Perkataan kita harus menghitung 243 * 256 +78, yang setara dengan 62.286. Tidak terlihat sangat jelas, bukan? Bayangkan menemukan nilai byte lapan pembolehubah panjang dan anda akan melihat mengapa notasi perpuluhan bukanlah pilihan terbaik untuk komputer binari.

Hex ? What?

The hexadecimal notation is almost universally used in computing - and not without a reason. There are sixteen hex digits - 0 to 9, and A to F (which correspond to decimal values 10 to 15), and each hex digit represents exactly four bits. Exactly two hex digits represent a byte, which can have a value from 00 to FF (that is from 0 to 255 decimal). In order to find a hex value of a multi-byte object, you would concatenate its bytes, for example, bytes 58 A4 1B FE constitute a four-byte value 58A41BFE (or FE1BA458 if the computer uses the reverse byte ordering).

But why hexadecimal? Can't we just use good old decimal numbers? Well, they would be fine for a decimal computer, but most contemporary computers are binary and work on bits and bytes. A decimal digit represents approximately 3.3 bits, and this makes arithmetic too complicated. Let's assume we have two bytes with decimal values 243 and 78. What will be the value of the two-byte word? 24378? No, this method works with hexadecimal digits only. To find the decimal value of the word we must compute 243*256+78, which equals to 62286. Does not look very obvious, does it? Imagine finding a value of an eight-byte long variable and you will see why the decimal notation is not the best choice for binary computers.

No comments:

Post a Comment