Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Easy question about formatting a string

Easy question about formatting a string

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewHSKid
    wrote on last edited by
    #1

    Hi everyone, Just a quick question. Is there a way to display binary when formatting a string? I know %d is decimal, %X is hex....is there one that even exists for binary? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

    RaviBeeR D W 3 Replies Last reply
    0
    • N NewHSKid

      Hi everyone, Just a quick question. Is there a way to display binary when formatting a string? I know %d is decimal, %X is hex....is there one that even exists for binary? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      There isn't a ready-made format specifier like %b that will format an integer in binary. You'll have to brew your own by walking the bits. /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      1 Reply Last reply
      0
      • N NewHSKid

        Hi everyone, Just a quick question. Is there a way to display binary when formatting a string? I know %d is decimal, %X is hex....is there one that even exists for binary? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        NewHSKid wrote: ...is there one that even exists for binary? No, you'll need to roll your own.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        1 Reply Last reply
        0
        • N NewHSKid

          Hi everyone, Just a quick question. Is there a way to display binary when formatting a string? I know %d is decimal, %X is hex....is there one that even exists for binary? Jimmy Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)

          W Offline
          W Offline
          WREY
          wrote on last edited by
          #4

          There are several ways. Here are a few. The example below will display the binary representation for the decimal 100. In addition to '#including' <bitset>, you'll also have to '#include' <limits> cout<<"\n 100: " <::bitset(85) <('A') < Ltrs = bitset<numeric_limits<unsigned int>::digits>('ABCD'); cout<<"\n \"ABCD\": " <

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups