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. 32bit to 4bytes(4*8bits)?

32bit to 4bytes(4*8bits)?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 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.
  • A Offline
    A Offline
    anju
    wrote on last edited by
    #1

    Hi,All In my application, i have to convert 32bit number to 4bytes(i.e each byte having 8bits). can any one help me.. thanks in advance regrads :rose: anju

    T C P A 4 Replies Last reply
    0
    • A anju

      Hi,All In my application, i have to convert 32bit number to 4bytes(i.e each byte having 8bits). can any one help me.. thanks in advance regrads :rose: anju

      T Offline
      T Offline
      Taka Muraoka
      wrote on last edited by
      #2

      int x = 0x01020304 ;
      const unsigned char* p = (unsigned char*) &x ;
      for ( int i=0 ; i < 4 ; ++i )
      cout << p[i] << endl ;


      You should save yourself and your company years of grief by shooting yourself through the head immediately. Believe me, in the long run it'll turn out better for everyone. - Tyto (at arstechnica) Awasu 1.0[^]: A free RSS reader with support for Code Project.

      1 Reply Last reply
      0
      • A anju

        Hi,All In my application, i have to convert 32bit number to 4bytes(i.e each byte having 8bits). can any one help me.. thanks in advance regrads :rose: anju

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        unsigned int i = 0x11223344;
        BYTE *pb = (BYTE *)&i;
        TRACE("%d, %d, %d, %d", pb[0], pb[1], pb[2], pb[3]);


        When history comes, it always takes you by surprise.

        Bobber!

        1 Reply Last reply
        0
        • A anju

          Hi,All In my application, i have to convert 32bit number to 4bytes(i.e each byte having 8bits). can any one help me.. thanks in advance regrads :rose: anju

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          int x = 0xfc12a15d;
          char c[4];
          for (int y = 0; y < 4; ++y)
          c[y] = (x & (0xff << (y * 8))) >> (y * 8);


          [

          ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

          1 Reply Last reply
          0
          • A anju

            Hi,All In my application, i have to convert 32bit number to 4bytes(i.e each byte having 8bits). can any one help me.. thanks in advance regrads :rose: anju

            A Offline
            A Offline
            anju
            wrote on last edited by
            #5

            Hi, Thanks for every one contributed inthis context. now my task is simple with your sugestions. once again thanks to all. :rose: anju

            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