How to convert decimal to Hex?

4/18/2000 12:07:12 AM
sybase.powerbuilder.general 62418 articles. 19 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 34
Get it on Google Play
Get it on Apple App Store

Usually it is customary to include body in your posts but here we go.

There are infinitely many ways to do this but the two I have used are
decimal to hex or decimal to binary to hex.  THe main advantage of the
latter is that it is extremely easy to go from binary to hex and from
decimal to binary.

First you need to know how many bytes are in the number you are dealing
with.  Each byte is two hexidecmal digits (digits isn't really the right
word but you know what I mean).  So for a two byte or 16 bit number there
are 4 hex digits.

hexidecimal digits go from 0 to 15 with fifteen = F  the number 16 decimal =
10 hex.  So to find each digit in the hex number you need to divide by 16 to
its position from the left minus one subtractr that number and do the next.
For example to turn 1000 into hex.

(% is the modulus operator in C)

1000 / 16^3 = 1000 / 4096 = 0

1000 % 16^3 = 1000

1000 / 16^2 = 1000 / 256 = 3

1000 % 256 = 232

232 / 16^1 = 232 / 16 = 14 = E

232 % 16 = 8

8 / 16^0 = 8 / 1 = 8

so the hex number is 03E8

This should be done in a loop but you're going to have to figure that one
out yourself. <> wrote in message

4/18/2000 12:30:23 PM

to convert ll_decin to hex populate a string as follows:

string ls_hexout, ls_decin
long ll_decin, ll_digit, ll_quotient

ls_decin = mle_1.text
ll_decin = long(ls_decin)
char lc_hexdigits[] = {'0','1','2','3','4','5','6','7', &

ll_digit = 7 // number of hex digits - 1
ls_hexout = "0x"
do while ll_digit >= 0
 ll_quotient = ll_decin / 16^ll_digit
 ll_decin = ll_decin - ll_quotient*(16^ll_digit)
 ls_hexout = ls_hexout + lc_hexdigits[ll_quotient + 1]
 ll_digit = ll_digit - 1

Messagebox("hex equivalent of " + ls_decin, ls_hexout)

Note that you can further optimize by keeping the results of "16^ll_digit"
in a local variable and only doing this calc once.
Millard[Team Sybase]
Power3 - Custom Enterprise Training wrote in message <5Q5klrMq$>...

4/18/2000 12:42:42 PM
Check out the numerical service from the PFC. Here's the code of the
of_hex(aul_decimal) function:

// Function:    of_Hex
// Access:    public
// Arguments:
// aul_decimal  Decimal value whose Hexadecimal representation needs to be
// Returns:   string
//      The Hexadecimal representation of the decimal number.
//      If any argument's value is NULL, function returns NULL.
// Description:   Determines the Hexadecimal representation of a Decimal
// Author: Lijun Yang
// Date:  4/7/97
// Revision History
// Date   Initials  Description of Change
// ----     --------  --------------------
// 4/7/97  L.Y.   Initial creation

string ls_hex=''
char lch_hex[0 to 15] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', &
       'a', 'b', 'c', 'd', 'e', 'f'}

If IsNull(aul_decimal) Then
 Return ls_hex
End If

 ls_hex = lch_hex[mod (aul_decimal, 16)] + ls_hex
 aul_decimal /= 16
Loop Until aul_decimal= 0

Return ls_hex


- Eric Aling [TeamSybase], AVALIX Information Systems, The Netherlands
  Eric's Home & PB Site @ <> schreef in berichtnieuws

4/18/2000 1:47:51 PM
The following code converts decimal to any base:

function string uf_10toBase(integer ai_base, ulong al_number10):

string ls_rem, ls_num
integer li_rem

    li_rem = Mod(al_number10,ai_base)
    if li_rem <= 9 then
        ls_rem = string(li_rem)
        ls_rem = Char(55+li_rem)
    end if
    ls_num = ls_rem + ls_num
    al_number10 = al_number10 / ai_base
LOOP UNTIL al_number10 = 0
return ls_num

and to convert from any base to decimal:

function ulong uf_Baseto10(integer ai_base, string as_number):

integer   i, li_max
unsignedlong ll_return, ll_num
string   ls_char

as_number = Upper(as_number)
li_max = Len(as_number)
for i = li_max to 1 step -1
    ls_char = Mid(as_number,i,1)
    if IsNumber(ls_char) then
        ll_num = integer(ls_char)
        ll_num = Asc(ls_char) - 55
    end if
    ll_num *= ai_base^(li_max-i)
    ll_return += ll_num
return ll_return



4/18/2000 2:41:04 PM

Similar Artilces:

How to convert decimal to hex?
Hi all, Please tell me how to convert a decimal number like 255 into its corresponding hex value. For example I want a result of "ff" for a decimal of 255. I've tried playing with the functions ord, hex, pack, ... but with no result. Thank you. Teddy's Center: Mail: $HEX = sprintf "%1x", $DEC; for more, perldoc -f sprintf Rgds, Connie ----- Original Message ----- From: "Octavian Rasnita" <> To: <> Sent: Friday, August 09, 2002 3:11 ...

help,how to convert hex to decimal?
The following converts from any base to decimal: function ulong uf_BaseTo10(integer ai_base, string as_number) integer i, li_max unsignedlong ll_return, ll_num string ls_char as_number = Upper(as_number) li_max = Len(as_number) for i = li_max to 1 step -1 ls_char = Mid(as_number,i,1) if IsNumber(ls_char) then ll_num = integer(ls_char) else ll_num = Asc(ls_char) - 55 end if ll_num *= ai_base^(li_max-i) ll_return += ll_num next return ll_return HTH Simon <> wrote in message...

Converting an image file from binary to hex decimal
I need an code that converts an image file from binary to hexadecimal and vise versa.  that is a requirement by the client thanks Here is some code.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no rights. ...

Any one have a PB function to convert hex to decimal?
Got some coworkers here trying to decipher some ugly file over here. All help appreciated - thanks! Nope...don't have one here. Why would you need anything like that? > Got some coworkers here trying to decipher some ugly file > over here. All help appreciated - thanks! > Got some coworkers here trying to decipher some ugly file > over here. All help appreciated - thanks! This extension of PFC's numerical service has it: ...

Convert Decimal To 2-Bytes Hex Value
Hi all, I want to convert with PB7 a decimal value (ie 1487) to a hex 2-bytes number. Simple question, but does anyone knows how to make it work Thank you in advance Alex /Open Support The easiest way I can think of is to write a small DLL that exports a function like the following: void IntToHex( int input, char * output ) { sprint( output, "%X", input ); } Then, declare a local external function in PB as follows: SUBROUTINE IntToHex( long input, REF string output ) LIBRARY "mysimpledll.dll" Sample PowerScript: String ls_hex l...

how to convert hex string to hex bytes?
Hi I've been trying and haven't found a solution for this yet and hopefully some of you can give me a direction to solve this problem. I have a string in hex representation i.e, 64 chars 'AB23FFFE.....' How can I convert it to 32 chars String where each byte is $AB $23 $FF $FE .... ? Even if I do it manually, can I store the hex(non ASCII) to String? Thanks for looking!! edwin wrote: > I have a string in hex representation i.e, 64 chars 'AB23FFFE.....' > How can I convert it to 32 chars String where each byte is $AB $23 $FF > $FE .... ? Th...

how to convert value with decimal point into value with decimal comma
Hello,  I like to know how I can change (for example) the value 55.55 into 55,55. (The system in my country is using comma's instead of points) I'm starting with  a string with the value "55.55" Then I will convert it to a double 55,55 Do I need the the system.Globalization namespace or is there just a simple solution?               Hi,If you are just going to use this format for display then it would be easy to do this:double dTemp;dTemp = 55.55;Response.Write(dTemp.ToString().Replace(".",","));H...

Cannot convert to decimal
I have a money field in SQL that when i try and get the sum of it i cannot convert it to decimal.  This was working now its not, and nothing was changed.Any reason for the error?    DECLARE @TEST decimal(10,2)SET @Test = (SELECT SUM(INV_Net) FROM abc.dbo.iSplit_Details WHERE LoanID='0000010604')Print @TestRETURNS: 160471.24----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Specified cast is not valid. Description: An unhandled exception occurred durin...

convert to Decimal
Hi, i get the error "Unable to cast object of type 'System.Decimal' to type 'System.String'." with my following coding: the Cap_Authorized data type is Decimal, how do i convert it ? private void LoadDBCpt(SqlConnection myConn) {SqlCommand SelectCmdCpt = new SqlCommand("SELECT isnull(Cap_Authorized,'-') as Cap_Authorized," + "isnull(Cap_PaidUp,'-') as Cap_PaidUp," +"isnull(Cap_Working,'-') as Cap_Working FROM tbl_Companies" + " WHERE Company_ID = '" + Request.QueryString["Company_I...

Convert to decimal
Hi, ASA select convert(decimal(5,2),0) returns 0.00 select convert(decimal(5,2),1.3) returns 1.3 select convert(decimal(5,2),0.3) returns .3 How can tell ASA to return 0.3 in case select convert(decimal(5,2),0.3) or when select convert(decimal(5,2),A/B) where A/B < 1 TIA Vesselin dbisqc and PHP module return .3 dbisqlg returns 0.3 "Veselin Ivanov" <> wrote in message news:428c3e76@forums-1-dub... > Hi, > ASA > > select convert(decimal(5,2),0) returns 0.00 > select convert(decimal(5,2),1.3) ret...

decimal to hex
Is there a way to create a SP or UDF that converts a decimal number to hexidecimal notation? run this in Query Analyzer SELECT CAST(255 as varbinary) SELECT CAST(10 as varbinary) SELECT CAST(26 as varbinary) cool eh?RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadableJason Brown - MVP, IIS very nice, thanks! Can I stick something like this in a Formula field? For example, say I have table Orders with columns OrderID (of type int) and OrderNumber. I tried putting in the Formula (under "design table") SELECT CAST(([Orde...

converting the values of a text box to decimal but with only two decimal spaces
I have a number like this ? 45,9098944     want to get only  45,91  what will be the best way to acomplish this, so far I been doing this, decimal AnnualAmount = Math.Round(Convert.ToDecimal(txtAnnualAmount.Text), 2);is this correct or is there a better way      Do you need it to be output somewhere, or you need to cut the amount of numbers after the decimal point, and store it in a variable, like you suggested? So far, seems absolutely correct to me. Andrey I need to displayed back to the page in a label,&nb...

Convert from hex
echo| perl -e ' $_=<>;s/%(..)/\\x$1/xg; print "$_"; ' This outputs http\x3A\x2F\\x2Fuploads\x2Fmf_aR_Ek_Ajnabi_-_01_-_Ek_Ajnabi_\x28Mama_Told_Me\x29\x28128Kbps\x29.mp3 Why does print not print the hex character in question? But, -bash-2.05b$ perl -e ' > print "http\x3A\x2F\\x2Fuploads\x2Fmf_aR_Ek_Ajnabi_-_01_-_Ek_Ajnabi_\x28Mama_Told_Me\x29\x28128Kbps\x29.mp3" > ' http:/...

Converting to Hex
Is there a simple way, like a one liner perhaps, that will give me the octal/hex value of a character? I need to look certain characters up, so I would like to be able to give it something like an 'a' or even "\n" and have it answer 141 or 012 (assuming UNIX). Thanks for your time. James check out sprintf() and ord() quickly for you example: ## hex perl -e 'printf("%x", ord("\n"))' ## oct perl -e 'printf("%o", ord("\n"))' > -----Original Message----- > From: James Edward Gray II [m...

Web resources about - How to convert decimal to Hex? - sybase.powerbuilder.general

List of converts to Buddhism - Wikipedia, the free encyclopedia
Ajahn Brahm (born 1951), Religious teacher and student of the late Thai monk Ajahn Chah . Currently he is the abbot of the Bodhinyana Monastery, ...

Facebook Timeline For Pages: 8 Million Converts, 29 Million To Go
... reach to 98 percent of users who liked its page, as well as to double its engagement rate, during a 28-day period. Dr. Pepper hasn’t yet converted ...

Facebook stock roundup: Execs offload more stock, directors convert shares
... Bowles, the former co-chair of the now-defunct National Commission on Fiscal Responsibility and Reform, and Reed Hastings, Netflix CEO, converted ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Coordinates - Calculate and Convert a Position on the App Store on iTunes
Get Coordinates - Calculate and Convert a Position on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Today’s apps gone free: BlockBear, Stock Grader, PDF Smart Convert and more
Block ads and other annoying content, take the emotion out of investing, and convert almost anything into a PDF with todays collection of apps ...

Ford patents rear wheel that converts into a unicycle
Filed under: Government/Legal , Green , Ford , Green Driving , Motorcycle , Electric Ford is thinking about allowing drivers to remove a rear ...

How to convert your old VHS tapes to DVD with this software
Remember those old VHS tapes you have sitting in the corner? Convert them into DVDs with this affordable software so you can easily watch them ...

Resources last updated: 1/18/2016 1:18:15 PM