Samsung Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
8
of 8 vote

If we know that the MAC address is well-formed (and should not handle error cases) then this will do

void MAC_to_ints(char *mac_addr, int arr[]) {
    sscanf(mac_addr, "%x:%x:%x:%x:%x:%x", arr, arr+1, arr+2, arr+3, arr+4, arr+5);
}

And it is demonstrating that you know a bit more about the C I/O library than others.

- Selmeczy, P├ęter December 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

appreciate

- srik545 January 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

great answer bro..

- shreyans August 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

#include <stdio.h>
#include <conio.h>

int main ()
{
    int a[6]; int ab,i=0;
    char mac[]="aa:bb:cc:12:23:34";
    char *aa=NULL;
    char delims[] = ":";
    
    getch();
    
    ab= (int)strtok(mac,delims);
    
    while (ab!=NULL)
    {
          printf(" %d  %s  ",ab,(char *)ab); 
          a[i]=ab;
          i++;  
          ab= (int) strtok(NULL,delims);
    }
getch();
}

- sanjay.2812 November 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

This Question is very much Simple,By Asking Such Question Interviewer wanted to check your Approach from Basic to Advance,In My Opinion,We should Give approach ,Idea rather than Direct Code or Answer.

1) Check Whether Given MAC Address is in Correct Format or not

ab:cd:ef:12:34:56

As per the IEEE Standard Above mentioned is correct

2)At locations 2,5,8,11,14 Check for the COLON Character,If it is not present then Show an error like "Invalid MAC address"


3) Every Value
Should be in the pair of two.


ab:cd:ef:2:4:56 <--Incorrect
ab:cd:ef:02:04:56<--Correct


4) Hex Values must be in the range of a to f,Otherwise Display an error like "Inavlid MAC address"

5) Now Tell him about Character Pair value to int Hex Value As asked in the Question.

I know my idea was so Basic but it may help to some Beginner @ Careercup

- Novice November 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

as A=10 B=11... F=15 this means AB=10*16+11=171 CD=12*16+13 EF=14*16+15 12=1*16+2=18 .... Put all these in a[0:5].. thats it..

- Anonymous November 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

int toInteger(char ch)
{
if(ch>='0'&&ch<='9')
{
return ch-'0';
}
else
return
ch-'a'+10;
}

int main()
{
int mac[6]={0},index,i;
i=index=0;
char *string="ab:cd:ef:12:34:56";
while(*string)
{
if(*string!=':')
{
mac[index]=mac[index]*16+toInteger(*string);
}
else
{
index++;
}
string++;
}
for(i=0;i<6;i++)
{
printf("%d ",mac[i]);
}
return 0;}

- Anonymous June 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

well done !!

- vijaymukilan July 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

mac address is a 48-bit interger.
unsigned char result[6];

restul[0] =>10<<4 | 11 = 171
restul[1] => 12<<4 | 13 = ...
...
restul[5] =>5<<4 + 6 = 86

When you do comparing, just comare the byte array elements 1 by 1.

- Anonymous November 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
int i, j;
char *mac_add = "ab:cd:ef:12:34:56";
char result[strlen(mac_add)];
j = 0;
for(i = 0; i <= strlen(mac_add); i++)
{
if(mac_add[i] != ':')
{
result[j++] = mac_add[i];
}
else
{
result[j++] = ',';
result[j++] = ' ';// Not required
// j++;
}
}
puts(result);
return 0;
}

- rasmiranjanbabu March 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef struct bin{
unsigned char a1:4;
unsigned char a2:4;
	} hex;

#pragma pack(1)
typedef struct {
hex d[6];
} max;
void Macasctohex()
{
	char mac[]="12:34:56:ab:cd:ef";
	 max opt;
	 int j=0;
	memset(&opt,0,sizeof(opt));
	for(int i=0;i<sizeof(mac)/sizeof(mac[0]);i+=3)
	{
	opt.d[j].a1=((mac[i+1]>='a')?(mac[i+1]-'a'+10):(mac[i+1]-'0'));
	opt.d[j++].a2=((mac[i]>='a')?(mac[i]-'a'+10):(mac[i]-'0'));
	}
}

- Charles December 29, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More