Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Hexadecimal
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Division-remainder in source base=== As with all bases there is a simple [[algorithm]] for converting a representation of a number to hexadecimal by doing integer division and remainder operations in the source base. In theory, this is possible from any base, but for most humans, only decimal and for most computers, only binary (which can be converted by far more efficient methods) can be easily handled with this method. Let d be the number to represent in hexadecimal, and the series h<sub>i</sub>h<sub>iβ1</sub>...h<sub>2</sub>h<sub>1</sub> be the hexadecimal digits representing the number. # i β 1 # h<sub>i</sub> β d mod 16 # d β (d β h<sub>i</sub>) / 16 # If d = 0 (return series h<sub>i</sub>) else increment i and go to step 2 "16" may be replaced with any other base that may be desired. The following is a [[JavaScript]] implementation of the above algorithm for converting any number to a hexadecimal in String representation. Its purpose is to illustrate the above algorithm. To work with data seriously, however, it is much more advisable to work with [[bitwise operators]]. <syntaxhighlight lang="javascript"> function toHex(d) { var r = d % 16; if (d - r == 0) { return toChar(r); } return toHex((d - r) / 16) + toChar(r); } function toChar(n) { const alpha = "0123456789ABCDEF"; return alpha.charAt(n); } </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Hexadecimal
(section)
Add topic