• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. How to achieve data conversion?

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 125
  • Views 15757
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to achieve data conversion?

bobbygang
bobbygang over 14 years ago

Hi,

Is there any function that can convert data bin to dec or hex in ocean?

Sincere

 

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    Converting an integer to hex is easy enough - sprintf(nil "%x" intVal) - and you can use sscanf() to go in the opposite direction. For binary strings, you could use the following code:

    /* abBinaryStrToInt.il

    Author A.D.Beckett
    Group Custom IC (UK), Cadence Design Systems Ltd.
    Language SKILL
    Date Feb 11, 2011
    Modified
    By

    Use bit field functions to convert to and from binary strings.

    Two functions:

    abBinaryStrToInt("1011") => 11
    abIntToBinaryStr(11 4) => "1011"

    ***************************************************

    SCCS Info: @(#) abBinaryStrToInt.il 02/11/11.11:56:48 1.1

    */


    /***************************************************************
    * *
    * abBinaryStrToInt(str) *
    * *
    * Take a string of 1s and 0s and convert to an integer. *
    * *
    ***************************************************************/


    procedure(abBinaryStrToInt(str "t")
    let((len (result 0))
    len=strlen(str)
    when(len>32 error("Cannot convert more than 32 bits"))
    for(i 1 len
    setqbitfield1(result case(substring(str i 1)
    ("1" 1)
    ("0" 0)
    (t error("Illegal character %s in binary string" substring(str i 1)))
    )
    len-i
    )
    )
    result
    )
    )


    /***************************************************************
    * *
    * abIntToBinaryStr(val @optional (bits 32)) *
    * *
    * Take an integer and convert to a string of 1s and 0s. *
    * An optional width of the resulting string can be given *
    * *
    ***************************************************************/


    procedure(abIntToBinaryStr(val @optional (bits 32) "xx")
    let(((result ""))
    when(bits>32 error("Cannot convert more than 32 bits"))
    for(i 0 (sub1 bits)
    result=strcat(if(onep(bitfield1(val i)) "1" "0") result)
    )
    result
    )
    )
      

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    Thank you very much. Then how can I trasform the string to variable. For example the result is x="01001"

    I want it become x=0b01001 then I can use x<1> x<2>........

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago
    Just use x=abBitStringToInt("01001")

    Sorry, I'd thought that was obvious which is why I didn't give an example. Mind you, your requirements weren't that clear so I wasn't 100% sure quite what you were after.

    Anyway, hopefully that will answer your question.

    Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • bobbygang
    bobbygang over 14 years ago

    I think your answer really help me. Now I have solved problem. I used to think that there must be some command to get the binary code. But after think through your answer and some test I found I can use x<1>,x<2> to directly express the code.

    Thank you a lot!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information