Solved Example of decimal to hexadecimal

February 6, 2015 at 13:13:30
Specs: Linux
An example of decimal to hexadecimal
A shortcut method.

Two methods.

One being less than 255 (Dec).
Two being more than 255 (Dec).

(1)
110 example number <255.
110/16 = 6.875 take the whole (6)
6*16 = 96
110 - 96 =
14 (remainder)
6
14 = e (Hex)

Combined
6e
6e (Hex) == 110 (Dec)

(2)
Example number 555 >255
555/16 = 34.6875
34*16 = 544
555 - 544 =
11 (remainder)
Different step.
34/16 =
2 remainder 2
Combined
= 22
11= b (Hex)
Combined
22b (Hex) == 555 (Dec)


message edited by lazybones2


See More: Example of decimal to hexadecimal

Report •


#1
February 6, 2015 at 16:25:03
✔ Best Answer
Not sure what you're asking for, and since you're Linux, this might not help, but here's a batch dhx conversion:

::dec-to-hex converter
@set hex=
@echo off & setlocal enabledelayedexpansion
set trimzer=1
set test=0123456789ABCDEF
(set hexout= )
::highest number convertable so far... 16^7-1 (268435455)
set /a strt=("1<<24")
set xx=%1
echo.

:aa
if %xx% equ 0 goto :xit
set /a dig="xx%%16"
set hexout=!test:~%dig%,1!%hexout%
set /a xx/=16
goto :aa

:xit
:trim off leading zeros unless "flagged" above
if defined trimzer for /L %%a in (1 1 10) do set hexout=!hexout: 0= !
echo %hexout%
:: this is best way i know to get externals "over" the endlocal barrier
endlocal & set hex=%hexout%


Report •
Related Solutions


Ask Question