• 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 SKILL
  3. print value as binary formated

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 15465
  • 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

print value as binary formated

DavidLou
DavidLou over 7 years ago

hello export,

maybe impossible but just trying, from SKLANGREF, the printf could only do %d, %o %x for integer value, is there a way to print the integer as Binary formatted? 

thanks,

David

  • Cancel
Parents
  • skillUser
    skillUser over 7 years ago

    Hi David,

    Here's one way of getting a binary string for an integer (I'm assuming 32-bits):

    
    str = ""
    num = 17 ;; test value
    for(i 0 31
      if(onep(bitfield1(num i))
        str=strcat("1" str) 
        str=strcat("0" str)
      )
    )
    
    str
    => "00000000000000000000000000010001"
    

    Hope this helps!

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to skillUser

    Very similar bit of code here that Lawrence beat me to it:

    /* 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
  • DavidLou
    DavidLou over 7 years ago in reply to Andrew Beckett

    perfect, thanks Lawrence and Andrew. 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • DavidLou
    DavidLou over 7 years ago in reply to Andrew Beckett

    perfect, thanks Lawrence and Andrew. 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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