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,521

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
Binary division restoring algorithm PIC 18F family atferrari Embedded Systems and Microcontrollers 1 05-29-2007 10:34 PM
8-bit binary adder using two 7483s and 7seg displays JoeyB Homework Help 3 03-22-2007 03:37 PM
Inputting a 4-bit binary # to a counter antseezee General Electronics Chat 5 03-14-2007 10:17 PM
help me pleas "asynchronous binary up counter " mmu Homework Help 6 12-27-2005 07:30 AM
I need to convert 6-digit BCD to binary PICmicro atferrari Programmer's Corner 4 10-19-2004 09:26 AM

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 08:00 AM.

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