All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner


Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
Thread Tools Display Modes
Old 05-15-2007, 02:55 PM
Dave_ Dave_ is offline
Junior Member
Join Date: Mar 2007
Posts: 28
Default How to concatenate binary in C

Hi all

My wish is to concatenate two binary numbers into one variable size vector, such as below:

A = 1111
B = 0000

C = A & B

C now equals 11110000

I found some solutions for C++, but none for C. Is it even possible?


Reply With Quote
Old 05-15-2007, 03:10 PM
recca02's Avatar
recca02 recca02 is offline
Senior Member
Join Date: Apr 2007
Location: India-22.35 N 82.68 E.
Posts: 1,211

well i dont know much abt c,
is concatenating strings different than concatenating binary numbers,
otherwise i think even a noob like me can do it myself.
Reply With Quote
Old 05-15-2007, 07:01 PM
Dave_ Dave_ is offline
Junior Member
Join Date: Mar 2007
Posts: 28

I was hoping there was a simple command to do it like '&' as used in VHDL. Perhaps I will have to do it the string way.
Reply With Quote
Old 05-15-2007, 10:44 PM
Papabravo's Avatar
Papabravo Papabravo is offline
Senior Member
Join Date: Feb 2006
Location: Michigan, USA (GMT-5)
Posts: 5,849

If you know the length of the strings you can combine them with shifting and boolean operations.
C = (A<<4) | B ;
Select All
With strings you need to use library functions. There are no string concatenation operators in C. Literal strings can be concatenated explicitly as initializers or printf arguments.
We never have time to do it right,
But we always have time to do it over.
Reply With Quote
Old 05-15-2007, 11:03 PM
Dave_ Dave_ is offline
Junior Member
Join Date: Mar 2007
Posts: 28

Oh damn. Ok, cheers for that Papabravo.
Reply With Quote
Reply   Post New Thread


Related Site Pages
Section Title
Worksheet Boolean algebra
Worksheet Binary math
Worksheet Numeration systems
Textbook Look-up tables : Principles Of Digital Computing
Video Lecture Boolean Algebra - Postulates - Digital
Video Lecture Digital Concepts & Terms - Digital
Textbook Binary count sequence : Sequential Circuits Counters
Textbook A Full-Adder : Combinational Logic Functions
Textbook 7-segment display : Digital Integrated Circuits
Textbook Octal and hexadecimal numeration : Numeration Systems

Similar Threads
Thread Thread Starter Forum Replies Last Post
Transferring a binary to a Maxim MAXQ610 chip MrSoftware Embedded Systems and Microcontrollers 4 10-30-2013 09:16 PM
I need help about Binary and BCD counter Mussawar Electronics Resources 7 04-07-2013 02:03 PM
1's and 2's complements of binary numbers PG1995 Math 13 10-18-2011 01:57 PM
Figured out quick equation to convert 6 bit binary nums count_volta Math 5 03-19-2011 12:47 AM
binary to decimal conversion program, having probs count_volta Programmer's Corner 17 12-18-2010 05:36 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:23 PM.

User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.