EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / how can shift four 8 bit value to one 32 bit variable

how can shift four 8 bit value to one 32 bit variable

|

Microcontroller › 8051 › how can shift four 8 bit value to one 32 bit variable

  • This topic has 3 replies, 3 voices, and was last updated 11 years, 5 months ago by VIJAYAKUMAR.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • January 3, 2014 at 7:37 am #2794
    chandru
    Participant
     
    hi , i want to shift four 8bit value to one 32 bit varible . i using below format . but the controller only getting first 16 bit value . please any one tell how can i shift
     
     
    unsigned char a=0x11,b=0x22,c=0x33,d=0x44;
    unsigned long int data=(a<<24)|(b<<16)|(c<<8)|(d);
     
    January 4, 2014 at 7:21 pm #10824
    AJISH ALFRED
    Participant

    Hi,

    Try this,

     

    data = data | a;

    data = data << 8;

     

    data = data | b;

    data = data << 8;

     

    data = data | c;

    data = data << 8;

     

    data = data | d;

     

    January 6, 2014 at 7:45 am #10827
    VIJAYAKUMAR
    Participant

    hi chandru

     

     

    problem in ur shifting is ur data is unsigned char , so this is the problem in ur shifting 

     take a,b,c,d , same type , long int u ill not get problem, other wise make casting and check 

     

    January 6, 2014 at 8:23 am #10828
    VIJAYAKUMAR
    Participant

    hi chandru

     

     

     

    unsigned long int data=(unsigned long int )(a<<24)|(unsigned long int )(b<<16)|(unsigned long int )(c<<8)|(unsigned long int )(d);

     

     

     

    try this one it should work !

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Siemens large industrial PLC parts June 15, 2025
  • Parts required for a personal project June 15, 2025
  • Cant log in to Easy PC forum June 15, 2025
  • Failure of polypropylene motor-run capacitors June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 15, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise